首先我們要先了解一下IP地址轉換為整型(嚴格來說應該說是長整型)的原理~
【轉換原理】
【PHP的互轉】
int ip
可以直接調用使用~
【Asp的互轉】
Function IP
Dim nIP
Dim nIndex
Dim arrIP
arrIP = Split(strIP
For nIndex =
If Not nIndex =
arrIP(nIndex) = arrIP(nIndex) * (
End If
nIP = nIP + arrIP(nIndex)
Next
IP
End Function
Function Num
Dim strIP
Dim nTemp
Dim nIndex
For nIndex =
nTemp = Int(nIP / (
strIP = strIP & nTemp & "
nIP = nIP
Next
strIP = Left(strIP
Num
End Function
【MsSQL的互轉】
/***************************************************************
* 將IP轉換為int型數字 |
* Code CreateBy abandonship|
**************************************************************/
CREATE FUNCTION [dbo]
@strIp varchar(
)RETURNS bigint
AS
BEGIN
declare @nIp bigint
set @nIp =
select
@nIp = @nIp + LEFT( @strIp
from(
select Id = cast(
union all select
union all select
union all select
) as T
return (@nIp)
END
/***************************************************************
* 將int型數字轉換為IP |
* Code CreateBy abandonship|
**************************************************************/
CREATE FUNCTION [dbo]
@nIp bigint
)RETURNS varchar(
As
BEGIN
declare @strIp varchar(
set @strIp =
select
@strIp = @strIp +
from(
select ID = cast(
union all select
union all select
union all select
) as T
return(stuff(@strIp
END
【MySQL的互轉】
IP轉為整型: select INET_ATON (IP地址) 和 整型轉為IP: select INET_NTOA ( IP的整型數值 )
可以直接調用使用~
From:http://tw.wingwit.com/Article/program/PHP/201311/21328.html