Home > php教程 > php手册 > ip网段转换程序,把ip地址转换成相对就的整数

ip网段转换程序,把ip地址转换成相对就的整数

WBOY
Release: 2016-05-25 16:42:50
Original
1303 people have browsed it

<?php
mysql_connect(&#39;localhost&#39;, &#39;root&#39;, &#39;root&#39;);
mysql_select_db(&#39;dfd&#39;);
$array = file("ip.txt");
foreach ($array as $k) {
    list($ip, $s) = explode(&#39;/&#39;, $k);
    $ipe = str_replace(&#39;.0&#39;, &#39;.255&#39;, $ip);
    $ipint = iptoint($ip);
    $ipinte = iptoint($ipe);
    //echo iptoint($ip) .&#39;-&#39;.iptoint($ipe),&#39;<br />&#39;;
    $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(&#39;" . $arr[0] . "&#39;,&#39;" . $arr[1] . "&#39;,&#39;" . $arr[2] . "&#39;,&#39;" . $arr[3] . "&#39;)") or die(mysql_error());
    }
}
Copy after login


Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Recommendations
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template