Created
October 7, 2014 16:28
-
-
Save ctrlcctrlv/5daa13997e44dabb0e72 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
function less_ip($ip) { | |
$ipv6 = (strstr($ip, ':') !== false); | |
$in_addr = inet_pton($ip); | |
if ($ipv6) { | |
// Not sure how many to mask for IPv6, opinions? | |
$mask = inet_pton('ffff:ffff:ffff:ffff:ffff:0:0:0'); | |
} else { | |
$mask = inet_pton('255.255.0.0'); | |
} | |
$final = inet_ntop($in_addr & $mask); | |
return str_replace(array(':0', '.0'), array(':x', '.x'), $final); | |
} | |
function less_hostmask($hostmask) { | |
$parts = explode('.', $hostmask); | |
if (sizeof($parts) < 3) | |
return $hostmask; | |
$parts[0] = 'x'; | |
$parts[1] = 'x'; | |
return implode('.', $parts); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment