note 101578 deleted from function.gethostbyname by danbrown
| From: | danbrown@php.net | Date: | Mon, 27 Dec 2010 16:37:37 +0000 |
| Subject: | note 101578 deleted from function.gethostbyname by danbrown | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-175237@lists.php.net to get a copy of this message | ||
Note Submitter: Steffen
----
got the solution from nirazuelos running for vista:
function getAddrByHost($host, $timeout = 3) {
exec("nslookup -timeout=3 -retry=1 ".$host,$output);
$ip="";
do {
$ipguess=array_pop($output);
if(substr($ipguess,0,7)=="Address") $ip=trim(strstr($ipguess," "));
} while (isset($output[0]) and ($ip=="") and ($ipguess<>""));
return $ip;
}
- I removed the preg dependency as this might not work with older/formerly configured php versions
- also nslookup returns your own ip somewhere in the results - frustrating, when your host times out
- do not want to have this in my results - that is why we have ipguess<>""
- it is definitely more precise as gethostbyname
the price is:
- nslookup on vista seems to ignore the timeout and retry options I still left in there