包含phpipv4地址归属地数据库的词条

本文目录一览:

php用IP查询归属地

class ip_location

{

function init()

{

$this-wrydat = ‘ip_area.dat’;

$this-fp = fopen($this-wrydat, ‘rb’);

$this-getipnumber();

$this-getwryversion();

$this – REDIRECT_MODE_0 = 0;

$this – REDIRECT_MODE_1 = 1;

$this – REDIRECT_MODE_2 = 2;

}

function get($str)

{

return $this-$str;

}

function set($str,$val)

{

$this-$str = $val;

}

function getbyte($length,$offset=null)

{

!is_null($offset) fseek($this-fp, $offset, SEEK_SET);

return fread($this-fp, $length);

}

function packip($ip)

{

return pack(‘N’, intval(ip2long($ip)));

}

function getlong($length=4, $offset=null)

{

$chr=null;

for($c=0;$length%4!=0$c(4-$length%4);$c++)

{

$chr .= chr(0);

}

$var = unpack( ‘Vlong’, $this-getbyte($length, $offset).$chr);

return $var[‘long’];

}

function getwryversion()

{

$length = preg_match(“/coral/i”,$this-wrydat)?26:30;

$this-wrydat_version = $this-getbyte($length, $this-firstip-$length);

}

function getipnumber()

{

$this-firstip = $this-getlong();

$this-lastip = $this-getlong();

$this-ipnumber = ($this-lastip-$this-firstip)/7+1;

}

function getstring($data=”, $offset=NULL)

{

$char = $this-getbyte(1,$offset);

while(ord($char) 0)

{

$data .= $char;

$char = $this-getbyte(1);

}

return $data;

}

function iplocaltion($ip)

{

$ip = $this-packip($ip);

$low = 0;

$high = $this-ipnumber-1;

$ipposition = $this-lastip;

while($low = $high)

{

$t = floor(($low+$high)/2);

if($ip strrev($this-getbyte(4,$this-firstip+$t*7)))

$high = $t – 1;

else

{

if($ip strrev($this-getbyte(4,$this-getlong(3))))

$low = $t + 1;

else

{

$ipposition = $this-firstip+$t*7;

break;

}

}

}

return $ipposition;

}

function getarea()

{

$b = $this-getbyte(1);

switch(ord($b))

{

case $this – REDIRECT_MODE_0 :

return ”;

break;

case $this – REDIRECT_MODE_1:

case $this – REDIRECT_MODE_2:

return $this-getstring(”,$this-getlong(3));

break;

default:

return $this-getstring($b);

break;

}

}

function getiplocation($ip)

{

$ippos = $this-iplocaltion($ip);

$this-ip_range_begin = long2ip($this-getlong(4,$ippos));

$this-ip_range_end = long2ip($this-getlong(4,$this-getlong(3)));

$b = $this-getbyte(1);

switch(ord($b))

{

case $this – REDIRECT_MODE_1:

$b = $this-getbyte(1,$this-getlong(3));

if(ord($b) == $this – REDIRECT_MODE_2)

{

$countryoffset = $this-getlong(3);

$this-area = $this-getarea();

$this-country = $this-getstring(”,$countryoffset);

}

else

{

$this-country = $this-getstring($b);

$this-area = $this-getarea();

}

break;

case $this – REDIRECT_MODE_2:

$countryoffset = $this-getlong(3);

$this-area = $this-getarea();

$this-country = $this-getstring(”,$countryoffset);

break;

default:

$this-country = $this-getstring($b);

$this-area = $this-getarea();

break;

}

}

}

—————————————————————

调用方法:

$iploca = new ip_location;

$iploca – init();

$iploca – getiplocation($ip);

$area[‘country’] = str_replace(array(‘CZ88.NET’), ”, $iploca – get(‘country’));

$area[‘area’] = str_replace(array(‘CZ88.NET’), ”, $iploca – get(‘area’));

$area[‘country’]==” $area[‘country’]=’未知’;

$area[‘area’]==” $area[‘area’]=’未知’;

return $area;

php怎样获取本机的ipv4地址

// 通过$_SERVER变量

echo $_SERVER[‘SERVER_ADDR’];

// 通过执行操作符,等同于在命令行下执行该命令,要获取ip的根据返回内容截取

$output = `ipconfig`;

echo ‘pre’.$output.’/pre’;

// 通过system函数,功能与执行操作符一样

echo ‘pre’;

$last_line = system(‘ipconfig’, $retval);

echo ‘

/pre

hr /Last line of the output: ‘ . $last_line . ‘

hr /Return value: ‘ . $retval;

php获取了ip地址,用php怎么获取ip的地理位置?请大虾赐教!

用纯真ip数据库啊,这里有个资料是介绍php操作纯真ip数据库的,是原查询吧query8.com里提取出来的,用时先去网上搜纯真ip数据库下载,查询吧php版读取纯真ip数据库源码

原创文章,作者:OCNK,如若转载,请注明出处:https://www.506064.com/n/137784.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
OCNKOCNK
上一篇 2024-10-04 00:18
下一篇 2024-10-04 00:18

相关推荐

  • cmd看地址

    本文将从多个方面详细阐述cmd看地址,包括如何查看本机IP地址、如何查看路由器IP、如何查看DNS服务器IP等等。 一、查看本机IP地址 要查看本机IP地址,首先需要打开cmd窗口…

    编程 2025-04-29
  • Python 常用数据库有哪些?

    在Python编程中,数据库是不可或缺的一部分。随着互联网应用的不断扩大,处理海量数据已成为一种趋势。Python有许多成熟的数据库管理系统,接下来我们将从多个方面介绍Python…

    编程 2025-04-29
  • openeuler安装数据库方案

    本文将介绍在openeuler操作系统中安装数据库的方案,并提供代码示例。 一、安装MariaDB 下面介绍如何在openeuler中安装MariaDB。 1、更新软件源 sudo…

    编程 2025-04-29
  • 尚硅谷官网地址用法介绍

    尚硅谷是国内一家领先的技术培训机构,提供了众多IT职业的培训,包括Java、Python、大数据、前端、人工智能等方向。其官网地址为http://www.atguigu.com/。…

    编程 2025-04-29
  • 数据库第三范式会有删除插入异常

    如果没有正确设计数据库,第三范式可能导致删除和插入异常。以下是详细解释: 一、什么是第三范式和范式理论? 范式理论是关系数据库中的一个规范化过程。第三范式是范式理论中的一种常见形式…

    编程 2025-04-29
  • leveldb和unqlite:两个高性能的数据库存储引擎

    本文将介绍两款高性能的数据库存储引擎:leveldb和unqlite,并从多个方面对它们进行详细的阐述。 一、leveldb:轻量级的键值存储引擎 1、leveldb概述: lev…

    编程 2025-04-28
  • Python怎么导入数据库

    Python是一种高级编程语言。它具有简单、易读的语法和广泛的库,让它成为一个灵活和强大的工具。Python的数据库连接类型可以多种多样,其中包括MySQL、Oracle、Post…

    编程 2025-04-28
  • Idea2022变更Git地址

    本文将从以下几个方面对Idea2022变更Git地址进行详细阐述: 一、GitHub上修改Git仓库地址 1、登录GitHub,找到需要修改的Git仓库 2、在代码页面点击右上角的…

    编程 2025-04-28
  • Think-ORM数据模型及数据库核心操作

    本文主要介绍Think-ORM数据模型建立和数据库核心操作。 一、模型定义 Think-ORM是一个开源的ORM框架,用于简化在PHP应用中(特别是ThinkPHP)与关系数据库之…

    编程 2025-04-27
  • electron-egg打包后请求地址错误解决方法用法介绍

    本文将从多个方面对electron-egg打包后请求地址错误进行详细阐述,并给出解决方法。 一、electron-egg打包后请求地址错误的表现 在使用 electron-egg …

    编程 2025-04-27

发表回复

登录后才能评论