包含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/zh-hk/n/137784.html

(0)
打賞 微信掃一掃 微信掃一掃 支付寶掃一掃 支付寶掃一掃
OCNK的頭像OCNK
上一篇 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

發表回復

登錄後才能評論