<?php
mysql_connect('localhost', 'root', 'root');
mysql_select_db('dfd');
$array = file("ip.txt");
foreach ($array as $k) {
list($ip, $s) = explode('/', $k);
$ipe = str_replace('.0', '.255', $ip);
$ipint = iptoint($ip);
$ipinte = iptoint($ipe);
//echo iptoint($ip) .'-'.iptoint($ipe),'<br />';
$s = array(
$ip,
$ipe,
$ipint,
$ipinte
);
save($s);
}
function iptoint($ip) {
$ipa = explode(".", $ip);
$ipn = $ipa[0] * 16777216 + $ipa[1] * 65536 + $ipa[2] * 256 + $ipa[3];
return $ipn;
}
function save($arr) {
if (count($arr) > 3) {
print_r($arr);
mysql_query("insert into ip(ips教程,ipe,ipsint,ipeint)values('" . $arr[0] . "','" . $arr[1] . "','" . $arr[2] . "','" . $arr[3] . "')") or die(mysql_error());
}
}
登录后复制