note 67531 added to function.ip2long
| From: | GaryRogers at osu1 dot php dot net | Date: | Thu, 08 Jun 2006 16:54:06 +0000 |
| Subject: | note 67531 added to function.ip2long | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-113853@lists.php.net to get a copy of this message | ||
Here is a function that will generate a random ip address by class (A, B, C, D, or E) and can also
generate addresses in the private address scheme for each class:
function random_ip($class = 'A', $private = false){
$ip = array();
// handle the ip class
switch ($class){
case 'A':
default:
$ip[0] = (!$private) ? rand(1, 126) : 10;
$ip[1] = rand(0, 255);
$ip[2] = rand(0, 255);
$ip[3] = rand(1, 254);
break;
case 'B':
$ip[0] = (!$private) ? rand(128, 191) : 172;
$ip[1] = (!$private) ? rand(1, 255) : rand(16, 31);
$ip[2] = rand(0, 255);
$ip[3] = rand(1, 254);
break;
case 'C':
$ip[0] = (!$private) ? rand(192, 223) : 192;
$ip[1] = (!$private) ? rand(0, 255) : 168;
$ip[2] = rand(1, 254);
$ip[3] = rand(1, 254);
break;
case 'D':
$ip[0] = rand(224, 293);
$ip[1] = rand(0, 255);
$ip[2] = rand(0, 255);
$ip[3] = rand(0, 255);
break;
case 'E':
$ip[0] = rand(240, 254);
$ip[1] = rand(0, 255);
$ip[2] = rand(0, 255);
$ip[3] = rand(0, 254);
break;
}
return implode('.', $ip);
}
----
Server IP: 64.71.164.2
Probable Submitter: 71.32.228.156
----
X-Spam-Status: No, hits=3.1 required=5.0 tests=DATE_MISSING,FROM_NO_LOWER
autolearn=no version=2.64
----
Manual Page -- http://www.php.net/manual/en/function.ip2long.php
Edit -- http://master.php.net/note/edit/67531
Del: integrated -- http://master.php.net/note/delete/67531/integrated
Del: useless -- http://master.php.net/note/delete/67531/useless
Del: bad code -- http://master.php.net/note/delete/67531/bad+code
Del: spam -- http://master.php.net/note/delete/67531/spam
Del: non-english -- http://master.php.net/note/delete/67531/non-english
Del: in docs -- http://master.php.net/note/delete/67531/in+docs
Del: other reasons-- http://master.php.net/note/delete/67531
Reject -- http://master.php.net/note/reject/67531
Search -- http://master.php.net/manage/user-notes.php