/usr/share/php/test/Net_IPv4/tests/MyIPv4.php is in php-net-ipv4 1.3.4-1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 | <?php
class MyIPv4 {
public function validateIP($ip) {
$quad = split('\.', $ip);
if (count($quad) != 4) {
return false;
}
foreach($quad as $q) {
if (!is_numeric($q)) {
return false;
} else if (intval($q) < 0 || intval($q) > 255) {
return false;
}
}
return true;
}
public function atoh($ip) {
$quad = split('\.', $ip);
$new = array();
foreach($quad as $k => $v) {
$n = str_pad(dechex($v), 2, "0", STR_PAD_LEFT);
$new[$k] = $n;
#var_dump($n);
}
return implode($new);
}
public function htoa($ip) {
$quad = str_split($ip, 2);
if (count($quad) != 4) {
return false;
}
$new = array();
foreach($quad as $k => $v) {
$new[$k] = hexdec($v);
#var_dump($n);
}
return $new[0].'.'.$new[1].'.'.$new[2].'.'.$new[3];
}
}
?>
|