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 は tuis_to_subnetformats()が出力したものを使用する. // $ip の内容の形式はチェックしない.これは呼び出し側の責任. // function tuis_match_ipaddr($ip, $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; } function tuis_randstr($len=8, $lowcase=false) { global $BaseChar; if ($lowcase) $rndmax = 25; else $rndmax = strlen($BaseChar) - 1; $return = ""; for($i=0; $i<$len; $i++) { $return .= $BaseChar{mt_rand(0, $rndmax)}; } return $return; } ?>