如何查询IP116226221123ip地址的地理位置查询

ipdata类源码
define('__QQWRY__', dirname(__FILE__) . &/qqwry.dat&);
class ipdata {
var $StartIP = 0;
var $EndIP = 0;
var $Country = '';
var $Local = '';
var $CountryFlag = 0;
var $FirstStartIp = 0;
var $LastStartIp = 0;
var $EndIpOff = 0;
function getStartIp($RecNo) {
$offset = $this-&FirstStartIp + $RecNo * 7;
@fseek($this-&fp, $offset, SEEK_SET);
$buf = fread($this-&fp, 7);
$this-&EndIpOff = ord($buf[4]) + (ord($buf[5]) * 256) + (ord($buf[6]) * 256 * 256);
$this-&StartIp = ord($buf[0]) + (ord($buf[1]) * 256) + (ord($buf[2]) * 256 * 256) + (ord($buf[3]) * 256 * 256 * 256);
return $this-&StartIp;
function getEndIp() {
@fseek($this-&fp, $this-&EndIpOff, SEEK_SET);
$buf = fread($this-&fp, 5);
$this-&EndIp = ord($buf[0]) + (ord($buf[1]) * 256) + (ord($buf[2]) * 256 * 256) + (ord($buf[3]) * 256 * 256 * 256);
$this-&CountryFlag = ord($buf[4]);
return $this-&EndIp;
function getCountry() {
switch ($this-&CountryFlag) {
$this-&Country = $this-&getFlagStr($this-&EndIpOff + 4);
$this-&Local = (1 == $this-&CountryFlag) ? '' : $this-&getFlagStr($this-&EndIpOff + 8);
$this-&Country = $this-&getFlagStr($this-&EndIpOff + 4);
$this-&Local = $this-&getFlagStr(ftell($this-&fp));
function getFlagStr($offset) {
$flag = 0;
while (1) {
@fseek($this-&fp, $offset, SEEK_SET);
$flag = ord(fgetc($this-&fp));
if ($flag == 1 || $flag == 2) {
$buf = fread($this-&fp, 3);
if ($flag == 2) {
$this-&CountryFlag = 2;
$this-&EndIpOff = $offset - 4;
$offset = ord($buf[0]) + (ord($buf[1]) * 256) + (ord($buf[2]) * 256 * 256);
if ($offset & 12) {
return '';
@fseek($this-&fp, $offset, SEEK_SET);
return $this-&getStr();
function getStr() {
$str = '';
while (1) {
$c = fgetc($this-&fp);
if (ord($c[0]) == 0) {
$str .= $c;
return iconv('gbk', 'utf-8', $str);
function geop($dotip = '') {
if (!$dotip) {
if (preg_match(&/^(127)/&, $dotip)) {
$this-&Country = '本地网络';
} else if (preg_match(&/^(192)/&, $dotip)) {
$this-&Country = '局域网';
$ip = $this-&IpToInt($dotip);
$this-&fp = fopen(__QQWRY__, &rb&);
if ($this-&fp == NULL) {
$szLocal = &OpenFileError&;
@fseek($this-&fp, 0, SEEK_SET);
$buf = fread($this-&fp, 8);
$this-&FirstStartIp = ord($buf[0]) + (ord($buf[1]) * 256) + (ord($buf[2]) * 256 * 256) + (ord($buf[3]) * 256 * 256 * 256);
$this-&LastStartIp = ord($buf[4]) + (ord($buf[5]) * 256) + (ord($buf[6]) * 256 * 256) + (ord($buf[7]) * 256 * 256 * 256);
$RecordCount = floor(($this-&LastStartIp - $this-&FirstStartIp) / 7);
if ($RecordCount &= 1) {
$this-&Country = &FileDataError&;
fclose($this-&fp);
$RangB = 0;
$RangE = $RecordCount;
while ($RangB & $RangE - 1) {
$RecNo = floor(($RangB + $RangE) / 2);
$this-&getStartIp($RecNo);
if ($ip == $this-&StartIp) {
$RangB = $RecNo;
if ($ip & $this-&StartIp) {
$RangB = $RecNo;
$RangE = $RecNo;
$this-&getStartIp($RangB);
$this-&getEndIp();
if (($this-&StartIp &= $ip) && ($this-&EndIp &= $ip)) {
$this-&getCountry();
$this-&Country = '未知';
$this-&Local = '';
fclose($this-&fp);
function IpToInt($Ip) {
$array = explode('.', $Ip);
$Int = ($array[0] * 256 * 256 * 256) + ($array[1] * 256 * 256) + ($array[2] * 256) + $array[3];
return $Int;
require &./util/ipdata/ipdata.class.php&;
$ip = '220.177.9.69';
$ipdata = new ipdata();
$ipdata-&geop($ip);
echo $ipdata-&Country.$ipdata-&L
文/hopevow(简书作者)
原文链接:/p/b
著作权归作者所有,转载请联系作者获得授权,并标注“简书作者”。
参考知识库
* 以上用户言论只代表其个人观点,不代表CSDN网站的观点或立场
访问:16995次
排名:千里之外
原创:69篇
转载:16篇
(3)(14)(8)(24)(5)(5)(1)(12)(1)(1)(6)(1)(3)(1)(1)(2)黑客常用的方法-如何查询对方IP地址_百度文库
两大类热门资源免费畅读
续费一年阅读会员,立省24元!
黑客常用的方法-如何查询对方IP地址
上传于|0|0|文档简介
&&实施攻击的初步一般是要查到欲攻击目标的IP地址。查他人IP地址的方法
阅读已结束,如果下载本文需要使用0下载券
想免费下载更多文档?
定制HR最喜欢的简历
下载文档到电脑,查找使用更方便
还剩4页未读,继续阅读
定制HR最喜欢的简历
你可能喜欢}

我要回帖

更多关于 ip地址的地理位置查询 的文章

更多推荐

版权声明:文章内容来源于网络,版权归原作者所有,如有侵权请点击这里与我们联系,我们将及时删除。

点击添加站长微信