Skip to content

Instantly share code, notes, and snippets.

@ctrlcctrlv
Created October 7, 2014 16:28
Show Gist options
  • Save ctrlcctrlv/5daa13997e44dabb0e72 to your computer and use it in GitHub Desktop.
Save ctrlcctrlv/5daa13997e44dabb0e72 to your computer and use it in GitHub Desktop.
<?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