0
I’d like to take the ip
who is in the dyndns
via PHP.
- It is possible to do this??
- If so, where do I start researching?
0
I’d like to take the ip
who is in the dyndns
via PHP.
0
Use the gethostbyname
, it will return the IP (Ipv4) corresponding to the address, example:
<?php
$ip = gethostbyname('meu_host_foo_bar.dyndns.org');
echo $ip;
An important detail is that if the gethostbyname
fail to get the ip address it will return the host itself which might confuse, so you can check like this:
<?php
$hostname = 'meu_host_foo_bar.dyndns.org';
$ip = gethostbyname($hostname);
if ($ip === $hostname) {
echo 'Falha ao obter o IP de: ', $hostname;
} else {
echo 'IP:', $ip;
}
Note that you can try using gethostbynamel
which will return a list in an array corresponding to the hostname passed:
<?php
$hostname = 'meu_host_foo_bar.dyndns.org';
$ips = gethostbynamel($hostname);
if (!$hosts) {
echo 'Falha ao obter o IP de: ', $hostname;
} else {
print_r($hosts);
}
Will return something like:
Array ( [0] => 192.0.34.166 )
That is, depending on the service you can return more than one, so you can check which is what you need. Failure will return false
.
My dear, I think it worked, just wait for confirmation here
Browser other questions tagged php
You are not signed in. Login or sign up in order to post.
Pick from where exactly, the dyndns offers various service. You want to convert the host as
seuhost.dyndns.com
to the ip number?– Guilherme Nascimento
exactly that William
– gabrielfalieri