【问题标题】:IP address representation in the Maxmind Geolitecity databaseMaxmind Geolitecity 数据库中的 IP 地址表示
【发布时间】:2011-07-07 08:57:43
【问题描述】:

我在 Mysql 数据库中有 Maxmind Geolitecity 数据库。

我可以看到像 startIpNumendIpNum 这样的字段。

这些字段的值如下所示:startIpNum 为 16777216,endIpNum 为 16777471

我的 ip 是 115.184.126.186,如何转换我的 ip 以匹配 startIpNumendIpNum

【问题讨论】:

    标签: php mysql ip-address


    【解决方案1】:

    按照 lmz 的建议使用 inet_aton(),或者在 php 中使用:

    http://php.net/manual/en/function.ip2long.php

    请注意,此函数返回一个有符号整数,含义范围从 − 2,147,483,648 到 2,147,483,647,我认为 maxmind geoip 数据库使用无符号整数 (0-4,294,967,295?),因此您需要向其添加 2,147,483,647 (2^31-1 )

    【讨论】:

    • 我很确定您可以使用 sprintf("%u", $ip2long($ip)) 在 PHP 中获取 long int 的无符号表示。
    • 可能,如果您想要字符串表示形式(在 SQL 连接中就是这种情况),则可以使用。
    【解决方案2】:

    试试 MySQL 中的inet_aton 函数。

    【讨论】:

      【解决方案3】:

      试试这样的:

      <?php 
       $ipadd="115.184.126.186";
       $ips = explode(".",$ipadd);
       $x=($ips[3] + $ips[2] * 256 + $ips[1] * 256 * 256 + $ips[0] * 256 * 256 * 256);
       echo $x;
      ?>
      

      把这个改成函数就好了..

      here是代码的结果

      【讨论】:

        【解决方案4】:

        尝试像这样转换它-

        SELECT INET_ATON("115.184.126.186");

        【讨论】:

          猜你喜欢
          • 2014-01-30
          • 2018-11-29
          • 1970-01-01
          • 2014-02-21
          • 2014-06-29
          • 1970-01-01
          • 1970-01-01
          • 2012-01-25
          • 1970-01-01
          相关资源
          最近更新 更多