I no longer work at that company and the last revision I had was in 2009.
but here is my last backup of that file:
<?php
/*
* Carrier Name Validation Class & Functions
* Last Update Date: 2009-09-09
*
* Changelog: 2009-09-09
* Added Old lists of Centennial IPs to the array
*
* Changelog: 2009-09-08
* Added Claro Subnets
* Removed Claro CDMA array: "200.50.12.98","66.50.210.239"
*
* Changelog: 2009-09-04
* Initial release... AT&T & Centennial Subnets
*
*/
class IPAddressSubnetSniffer {
var $allowed_subnets;
function IPAddressSubnetSniffer ($allowed_subnets) {
// "allowed_subnets" defaults to ALL allowed subnets
$this->allowed_subnets = $allowed_subnets ? $allowed_subnets : array(0);
$this->setup_binary_subnet_list();
}
function setup_binary_subnet_list() {
foreach ( $this->allowed_subnets as $sn ) {
unset($ip_octets);
unset($mask_octets);
if ( ! preg_match("/\//", $sn) ) {
// assume mask is "natural", create value for mask
$ip_octets = split("\.", $sn);
$ip_octets = array_pad($ip_octets, 4, 0);
foreach ( $ip_octets as $o ) {
if ($o != 0) {
$mask_octets[] = 255;
} else {
$mask_octets[] = 0;
}
}
} else {
// Do masking according to notation
list($ip, $mask) = split("/", $sn);
$ip_octets = split("\.", $ip);
if ( preg_match("/^\d\d*$/", $mask) ) {
for ( $m = 0; $m < $mask; $m++) {
$mask_octets .= "1";
}
$mask_octets = str_pad($mask_octets, 32, '0');
$mask_octets = preg_replace("/(\d{8})/", "$1.", $mask_octets);
$mask_octets = preg_replace("/\.$/", "", $mask_octets);
$mask_octets = split("\.", $mask_octets);
foreach ( $mask_octets as $k => $v) {
$mask_octets[$k] = bindec($v);
}
} else {
$mask_octets = split("\.", $mask);
}
}
unset($bin_sn);
unset($masks);
for ( $o = 0; $o < count($ip_octets); $o++ ) {
$bin_sn[] = $this->get_bin($ip_octets[$o] & $mask_octets[$o]);
$masks[] = $this->get_bin($mask_octets[$o]);
}
$subnets[] = join(".", $bin_sn);
$mask_list[] = join(".", $masks);
}
$this->binary_subnet_ips = $subnets;
$this->binary_subnet_masks = array_unique($mask_list);
return true;
}
function get_bin($number) {
return str_pad(decbin($number),8,'0',STR_PAD_LEFT);
return decbin($number);
}
function ip2bin( $ip ) {
$ip_octets = split("\.", $ip);
unset($bin_sn);
for ( $o = 0; $o < count($ip_octets); $o++ ) {
$bin_sn[] = $this->get_bin($ip_octets[$o]);
}
return join(".", $bin_sn);
}
function bin2ip( $ip ) {
$ip_octets = split("\.", $ip);
unset($bin_sn);
for ( $o = 0; $o < count($ip_octets); $o++ ) {
$bin_sn[] = bindec($ip_octets[$o]);
}
return join(".", $bin_sn);
}
function apply_mask( $ip, $mask ) {
$ip_octets = split("\.", $ip);
$mask_octets = split("\.", $mask);
unset($bin_sn);
for ( $o = 0; $o < count($ip_octets); $o++ ) {
$bin_sn[] = $this->get_bin(intval($ip_octets[$o]) & intval($mask_octets[$o]));
}
$subnet = join(".", $bin_sn);
return $subnet;
}
function ip_is_allowed( $ip ) {
foreach ( $this->binary_subnet_masks as $mask ) {
$subnet = $this->apply_mask( $ip, $this->bin2ip($mask) );
$out[] = $subnet;
}
// Need to walk through all the possible subnets that the given IP
// could be a part of. Just use "in_array()"
foreach ( $out as $net ) {
if ( in_array( $net, $this->binary_subnet_ips ) ) return true;
}
return false;
}
}
/*
* Validate Carriers Function
* Receives users IP address and returns the carrier based on the arrays of carriers IPs Gateways & Subnets
*/
function get_carrier($remote_address) {
$subnets = array('US,AT&T' => array("209.183.48.0 /22", "209.183.52.0 /22", "166.205.0.0 /17", "166.205.128.0 /17", "166.216.0.0 /16", "166.216.0.0 /16", "166.216.130.0 /24", "66.102.186.0 /24", "166.216.160.0 /23", "166.216.162.0 /24", "209.183.32.0 /24", "166.216.128.0 /23", "209.183.51.0 /24", "166.216.192.0 /23", "166.216.194.0 /24", "209.183.55.0 /24", "166.216.224.0 /23", "166.216.226.0 /24", "166.217.0.0 /16", "166.203.0.0 /16", "32.178.0.0 /16", "166.214.0.0 /16", "166.204.0.0 /16", "32.179.0.0 /16", "166.128.0.0 /16", "166.183.0.0 /16", "32.176.0.0 /16", "166.129.0.0 /16", "166.187.0.0 /16", "32.177.0.0 /16", "166.196.0.0 /14", "32.136.0.0 /13", "32.164.0.0 /14", "166.137.128.0 /17", "166.184.128.0 /17", "166.137.0.0 /17", "166.192.0.0 /14", "32.128.0.0 /13", "32.160.0.0 /14", "166.205.0.0 /17", "166.216.0.0 /17", "166.220.0.0 /17", "166.188.0.0 /15", "166.132.0.0 /15", "32.144.0.0 /13", "32.168.0.0 /14", "166.205.128.0 /17", "166.190.0.0 /15", "166.134.0.0 /15", "32.152.0.0 /13", "32.172.0.0 /14"),
'Centennial Wireless' => array("200.50.16.15","67.203.230.59","67.206.220.48","67.203.246.92","67.203.217.31","67.206.204.49","67.203.195.80","67.203.223.104","67.203.212.132", "67.206.196.107","67.206.204.241","67.206.233.189", "67.206.213.204","206.53.153.62","67.206.198.31","208.54.191.240","64.209.14.204","67.206.232.39","67.206.244.197","67.206.253.197","67.206.230.161","67.206.210.38","208.54.191.76","67.206.247.57", "64.212.200.0/21", "67.206.192.0/19", "67.203.192.0/18", "67.203.192.0/18", "67.203.192.0/18", "208.54.176.0/20", "64.213.112.0/20", "64.209.8.0/21", "67.206.224.0/19"),
'Claro GSM' => array("196.28.52.1","166.216.162","196.28.57.4"),
'Claro CDMA' => array("66.50.210.239","200.50.12.98", "63.135.240.0 /20", "66.50.208.0 /24", "66.50.149.0 /24", "66.50.110.0 /24", "66.50.204.0 /24", "66.50.203.0 /24", "66.50.202.0 /24", "66.50.201.0 /24", "66.50.205.0 /24"),
'Open Mobile' => array("67.215.111.210","67.215.111.213"),
'T-Mobile' => array("208.54.94.58","208.54.94.107","208.54.90.76","208.54.87.59"));
foreach($subnets as $carrier=>$subnet_array) {
$sniffer = new IPAddressSubnetSniffer($subnet_array);
if($sniffer->ip_is_allowed($remote_address)) {
return $carrier;
}
}
return false;
}