note 101578 added to function.gethostbyname

From: Date: Mon, 27 Dec 2010 11:53:00 +0000
Subject: note 101578 added to function.gethostbyname
Groups: php.notes 
Request: Send a blank email to php-notes+get-175217@lists.php.net to get a copy of this message
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 ---- Server IP: 69.147.83.197 Probable Submitter: 92.201.51.135 ---- Manual Page -- http://www.php.net/manual/en/function.gethostbyname.php Edit -- https://master.php.net/note/edit/101578 Del: integrated -- https://master.php.net/note/delete/101578/integrated Del: useless -- https://master.php.net/note/delete/101578/useless Del: bad code -- https://master.php.net/note/delete/101578/bad+code Del: spam -- https://master.php.net/note/delete/101578/spam Del: non-english -- https://master.php.net/note/delete/101578/non-english Del: in docs -- https://master.php.net/note/delete/101578/in+docs Del: other reasons-- https://master.php.net/note/delete/101578 Reject -- https://master.php.net/note/reject/101578 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#175217) next »