自定义函数如下,’.———————————————————–.’|
describtion: 将IP转换为int型数字 |’| Authors: abandonship
|’~———————————————————–~Function
IP2Num Dim nIP Dim nIndex Dim arrIP arrIP = Split For nIndex = 0 To 3 If
Not nIndex = 3 Then arrIP = arrIP * End If nIP = nIP + arrIP Next
IP2Num = nIPEnd Function
‘.———————————————————–.’|
describtion: 将int型数字转换为IP |’| Authors: abandonship
|’~———————————————————–~Function
Num2IP Dim strIP Dim nTemp Dim nIndex For nIndex = 3 To 0 Step -1 nTemp
= Int strIP = strIP & nTemp & “.” nIP = nIP – (nTemp * Next strIP =
Left – 1) Num2IP = strIP End Function

相对于MsSQL来说MySQL的转换方式比较简单,它和PHP一样也内置了两个函数IP转为整型:
select INET_ATON 和 整型转为IP: select INET_NTOA 可以直接调用使用~

假设IP为:w.x.y.z,则IP地址转为整型数字的计算公式为:intIP =
256*256*256*w + 256*256*新澳门31999 ,x + 256*y + z

首先我们要先了解一下IP地址转换为整型的原理~

PHP的转换方式比较简单,它内置了两个函数int ip2long 和 string
long2ip ( string $proper_address )可以直接调用使用~

:自定义函数如下,/****************************************************************将IP转换为int型数字
|*Code CreateBy abandonship |
**************************************************************/CREATE
FUNCTION [dbo].[ipToInt]RETURNS bigint AS BEGIN declare @nIp bigint
set @nIp = 0 select @nIp = @nIp + LEFT( @strIp, charindex*Id from(
select Id = cast(1*256*256*256 as bigint) union all select
1*256*256 union all select 1*256 union all select 1) as Treturn END
/****************************************************************将int型数字转换为IP
|*Code CreateBy abandonship |
**************************************************************/CREATE
FUNCTION [dbo].[intToIP]RETURNS varchar As BEGIN declare @strIp
varchar set @strIp = ” select @strIp = @strIp +’.’+ cast, @nIp =
@nIp%IDfrom( select ID = cast(1*256*256*256 as bigint) union all
select 1*256*256 union all select 1*256 union all select 1 ) as T
return END

发表评论

电子邮件地址不会被公开。 必填项已用*标注