SubnetMask $cider = $sub[0]; $nbyte = (int)($cider/8); $nbit = $cider - $nbyte*8; for ($i=0; $i<$nbyte; $i++) { $sub[$i] = 255; } if ($nbyte!=4) { $nsub = 0; $base = 128; for ($i=0; $i<$nbit; $i++) { $nsub += $base; $base = $base/2; } $sub[$nbyte] = $nsub; } } for ($i=0; $i<4; $i++) { if (!empty($ips[$i])) $return[$index]['ipaddr'][$i] = (int)$ips[$i]; else $return[$index]['ipaddr'][$i] = (int)0; if (!empty($sub[$i])) $return[$index]['subnet'][$i] = (int)$sub[$i]; else $return[$index]['subnet'][$i] = (int)0; } $index++; } return $return; } // // $ip が $ipaddr_subnetsの中に含まれるか検査する. // $ipaddr_subnets は jbxl_to_subnetformats()が出力したものを使用すること. // $ip の内容の形式はチェックしない.これは呼び出し側の責任. // function jbxl_match_ipaddr($ip, array $ipaddr_subnets) { $ipa = explode('.', $ip); if (empty($ipa)) return false; for ($i=1; $i<4; $i++) { if (empty($ipa[$i])) $ipa[$i] = 0; } foreach($ipaddr_subnets as $ipaddr_subnet) { $ips = $ipaddr_subnet['ipaddr']; $sub = $ipaddr_subnet['subnet']; $match_f = true; for ($i=0; $i<4; $i++) { $check1 = $ipa[$i] & $sub[$i]; $check2 = $ips[$i] & $sub[$i]; if ($check1 != $check2) { $match_f = false; break; } } if ($match_f) { //print_r($ips); //print_r($sub); return true; } } return false; } $JBXLBaseChar = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789"; function jbxl_randstr($len=8, $lowcase=false) { global $JBXLBaseChar; if ($lowcase) $rndmax = 25; else $rndmax = strlen($JBXLBaseChar) - 1; $return = ""; for($i=0; $i<$len; $i++) { $return .= $JBXLBaseChar{mt_rand(0, $rndmax)}; } return $return; } function jbxl_get_ipresolv_url($ip, $region='APNIC') { if (!preg_match('/(^\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})$/', $ip, $match)) return ''; if ($match[1]>255 or $match[2]>255 or $match[3]>255 or $match[4]>255) return ''; if ($match[1]=='127' or $match[1]=='10') return ''; if ($match[1]=='172' and $match[2]>='16' and $match[2]<='31') return ''; if ($match[1]=='192' and $match[2]=='168') return ''; if ($region=='JPNIC') { $url = 'http://whois.nic.ad.jp/cgi-bin/whois_gw?type=NET&key='.$ip; // JPNIC } else { $url = 'http://wq.apnic.net/apnic-bin/whois.pl?searchtext='.$ip; // APNIC } return $url; } } // !defined('JBXL_TOOLS_VER') ?>