note 90040 modified in function.gethostbyaddr by danbrown
| From: | danbrown@php.net | Date: | Thu, 02 Apr 2009 19:43:59 +0000 |
| Subject: | note 90040 modified in function.gethostbyaddr by danbrown | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-152770@lists.php.net to get a copy of this message | ||
The use of the shell command to speed things up seems to work very well, but I would suggest one
thing: you ARE executing a shell command, so it would seem to be a good idea to be absolutely sure
of your input. Something like this perhaps:
<?php
function gethost ($ip)
{
//Make sure the input is not going to do anything unexpected
//IPs must be in the form x.x.x.x with each x as a number
$testar = explode('.',$ip);
if (count($testar)!=4)
return $ip;
for ($i=0;$i<4;++$i)
if (!is_numeric($testar[$i]))
return $ip;
$host =
host $ip;
return (($host ? end ( explode (' ', $host)) : $ip));
}
?>
--was--
The use of the shell command to speed things up seems to work very well, but I would suggest one
thing: you ARE executing a shell command, so it would seem to be a good idea to be absolutely sure
of your input. Something like this perhaps:
function gethost ($ip)
{
//Make sure the input is not going to do anything unexpected
//IPs must be in the form x.x.x.x with each x as a number
$testar = explode('.',$ip);
if (count($testar)!=4)
return $ip;
for ($i=0;$i<4;++$i)
if (!is_numeric($testar[$i]))
return $ip;
$host = host $ip;
return (($host ? end ( explode (' ', $host)) : $ip));
}
http://php.net/manual/en/function.gethostbyaddr.php