ASP调用纯真IP库的代码,测试可用
<%
============================================
返回ip信息 disp_ipaddressdata(ip,0)
============================================
function look_ip(ip)
dim wry, iptype, qqwryversion, ipcounter
设置类对象
set wry = new tqqwry
开始搜索,并返回搜索结果
您可以根据 qqwry(ip) 返回值来判断该ip地址在中是否存在,如果不存在可以执行其他的一些操作
比如您自建一个数据库作为追捕等,这里我就不详细说明了
iptype = wry.qqwry(ip)
country:国家地区字段
localstr:省市及其他信息字段
look_ip =wry.country & "" & wry.localstr
look_ip = wry.country & ""
end function
============================================
返回ip信息 js调用
============================================
function disp_ipaddressdata(ip, stype)
dim wry, iptype
set wry = new tqqwry
iptype = wry.qqwry(ip)
select case stype
case 1 disp_ipaddressdata = ip
case 2 disp_ipaddressdata = wry.country
case 3 disp_ipaddressdata = wry.localstr
case else disp_ipaddressdata = wry.country & "" & wry.localstr
case else disp_ipaddressdata = wry.country
end select
end function
============================================
返回qqwry信息
============================================
function wryinfo()
dim wry, iptype, qqwry_tem(0), qqwry_tem1(1)
设置类对象
set wry = new tqqwry
iptype = wry.qqwry("255.255.255.254")
读取数据库版本信息
qqwry_tem(0) = wry.country & " " & wry.localstr
读取数据库ip地址数目
qqwry_tem1(1) = wry.recordcount + 1
wryinfo = qqwry_tem(0)& " " & qqwry_tem1(1)
end function
class tqqwry
============================================
变量声名
============================================
dim country, localstr, buf, offset
private startip, endip, countryflag
public qqwryfile
public firststartip, laststartip, recordcount
private stream, endipoff
============================================
类模块初始化
============================================
private sub class_initialize
country = ""
localstr = ""
startip = 0
endip = 0
countryflag = 0
firststartip = 0
laststartip = 0
endipoff = 0
qqwryfile = server.mappath("coralwry.dat") qq纯真ip库存放路径,要改为你的路径
end sub
============================================
ip地址转换成整数
============================================
function iptoint(ip)
dim iparray, i
iparray = split(ip, ".", -1)
for i = 0 to 3
if not isnumeric(iparray(i)) then iparray(i) = 0
if cint(iparray(i)) < 0 then iparray(i) = abs(cint(iparray(i)))
if cint(iparray(i)) > 255 then iparray(i) = 255
next
iptoint = (cint(iparray(0))*256*256*256) + (cint(iparray(1))*256*256) + (cint(iparray(2))*256) + cint(iparray(3))
end function
============================================
整数逆转ip地址
============================================
function inttoip(intvalue)
p4 = intvalue - fix(intvalue/256)*256
intvalue = (intvalue-p4)/256
p3 = intvalue - fix(intvalue/256)*256
intvalue = (intvalue-p3)/256
p2 = intvalue - fix(intvalue/256)*256
intvalue = (intvalue - p2)/256
p1 = intvalue
inttoip = cstr(p1) & "." & cstr(p2) & "." & cstr(p3) & "." & cstr(p4)
end function
============================================
获取开始ip位置
============================================
private function getstartip(recno)
offset = firststartip + recno * 7
stream.position = offset
buf = stream.read(7)
endipoff = ascb(midb(buf, 5, 1)) + (ascb(midb(buf, 6, 1))*256) + (ascb(midb(buf, 7, 1))*256*256)
startip = ascb(midb(buf, 1, 1)) + (ascb(midb(buf, 2, 1))*256) + (ascb(midb(buf, 3, 1))*256*256) + (ascb(midb(buf, 4, 1))*256*256*256)
getstartip = startip
end function
============================================
获取结束ip位置
============================================
private function getendip()
stream.position = endipoff
buf = stream.read(5)
endip = ascb(midb(buf, 1, 1)) + (ascb(midb(buf, 2, 1))*256) + (ascb(midb(buf, 3, 1))*256*256) + (ascb(midb(buf, 4, 1))*256*256*256)
countryflag = ascb(midb(buf, 5, 1))
getendip = endip
end function
============================================
获取地域信息,包含国家和和省市
============================================
private sub getcountry(ip)
if (countryflag = 1 or countryflag = 2) then
country = getflagstr(endipoff + 4)
if countryflag = 1 then
localstr = getflagstr(stream.position)
以下用来获取数据库版本信息
if ip >= iptoint("255.255.255.0") and ip <= iptoint("255.255.255.255") then
localstr = getflagstr(endipoff + 21)
country = getflagstr(endipoff + 12)
end if
else
localstr = getflagstr(endipoff + 8)
end if
else
country = getflagstr(endipoff + 4)
localstr = getflagstr(stream.position)
end if
过滤数据库中的无用信息
country = trim(country)
localstr = trim(localstr)
if instr(country, "cz88.net") then country = ""
if instr(localstr, "cz88.net") then localstr = ""
end sub
============================================
获取ip地址标识符
============================================
private function getflagstr(offset)
dim flag
flag = 0
do while (true)
stream.position = offset
flag = ascb(stream.read(1))
if(flag = 1 or flag = 2 ) then
buf = stream.read(3)
if (flag = 2 ) then
countryflag = 2
endipoff = offset - 4
end if
offset = ascb(midb(buf, 1, 1)) + (ascb(midb(buf, 2, 1))*256) + (ascb(midb(buf, 3, 1))*256*256)
else
exit do
end if
loop
if (offset < 12 ) then
getflagstr = ""
else
stream.position = offset
getflagstr = getstr()
end if
end function
============================================
获取字串信息
============================================
private function getstr()
dim c
getstr = ""
do while (true)
c = ascb(stream.read(1))
if (c = 0) then exit do
如果是双字节,就进行高字节在结合低字节合成一个字符
if c > 127 then
if stream.eos then exit do
getstr = getstr & chr(ascw(chrb(ascb(stream.read(1))) & chrb(c)))
else
getstr = getstr & chr(c)
end if
loop
end function
============================================
核心函数,执行ip搜索
============================================
public function qqwry(dotip)
dim ip, nret
dim rangb, range, recno
ip = iptoint (dotip)
set stream = createobject("adodb.stream")
stream.mode = 3
stream.type = 1
stream.open
stream.loadfromfile qqwryfile
stream.position = 0
buf = stream.read(8)
firststartip = ascb(midb(buf, 1, 1))
上一篇: 超实用:常用英文字体推荐