how to get ip from domain in php? -
(i exexute code in dos) code:
<?php $handle = fopen("domann.txt", "r"); if ($handle) { while (($line = fgets($handle)) !== false) { $ip = gethostbyname($line); echo "reading: ".$line. " ip: ".$ip ; } fclose($handle); } else { // error opening file. } ?>
i'd have this:
reading: www.abc.it ip: 211.195.239.122
the problem not in gethostbyname() function!! must in fgets($handle) return \n each line read
here solution:
$handle = fopen("file.txt", "r"); if ($handle) { while (($line = fgets($handle)) !== false) { $line=str_replace("\r\n","",$line); $ip = gethostbyname($line); echo "reading: ".$line." ip: ".$ip; echo "\n"; } fclose($handle); } else { echo "connection error"; }
hey there @luca i've found out why code i'snt working, because in domann.txt have named website likes http://google.com or http://www.google.com doesnt work, way works in www.google.com in domann.txt name website urls www. suffix , nothing more should fix . proof
Comments
Post a Comment