LOGO OA教程 ERP教程 模切知识交流 PMS教程 CRM教程 开发文档 其他文档  
 
网站管理员

ASP利用纯真数据库查询IP地理位置

admin
2010年7月13日 18:46 本文热度 5735
asp查询纯真ip的类,请保存为cz.asp[br]<% [br]class tqqwry [br]dim country,localstr,buf,offset [br]private startip,endip,countryflag [br]public firststartip,laststartip,recordcount,qqwryfile [br]private stream,endipoff [br][br]private sub class_initialize [br]country="" [br]localstr="" [br]startip=0 [br]endip=0 [br]countryflag=0 [br]firststartip=0 [br]laststartip=0 [br]endipoff=0 [br]qqwryfile=server.mappath("cz.dat") [br]end sub [br][br]public sub setpath(p) [br]qqwryfile = server.mappath(p) [br]end sub [br][br]function ip2int(ip) [br]dim iparray,i [br]iparray=split(ip,".",-1) [br]for i=0 to 3 [br]if not isnumeric(iparray(i)) then iparray(i)=0 [br]if cint(iparray(i))<0 then iparray(i)=abs(cint(iparray(i))) [br]if cint(iparray(i))>255 then iparray(i)=255 [br]next [br]ip2int=(cint(iparray(0))*256*256*256)+(cint(iparray(1))*256*256)+(cint(iparray(2))*256)+cint(iparray(3))'-1 [br]end function [br][br]function int2ip(intvalue) [br]p4=intvalue-fix(intvalue/256)*256 [br]intvalue=(intvalue-p4)/256 [br]p3=intvalue-fix(intvalue/256)*256 [br]intvalue=(intvalue-p3)/256 [br]p2=intvalue-fix(intvalue/256)*256 [br]intvalue=(intvalue-p2)/256 [br]p1=intvalue [br]int2ip=cstr(p1)&"."&cstr(p2)&"."&cstr(p3)&"."&cstr(p4) [br]end function [br][br]private function getstartip(recno) [br]offset=firststartip+recno * 7 [br]stream.position=offset [br]buf=stream.read(7) [br][br]endipoff=ascb(midb(buf,5,1))+(ascb(midb(buf,6,1))*256)+(ascb(midb(buf,7,1))*256*256) [br]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) [br]getstartip=startip [br]end function [br][br]private function getendip() [br]stream.position=endipoff [br]buf=stream.read(5) [br]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) [br]countryflag=ascb(midb(buf,5,1)) [br]getendip=endip [br]end function [br][br]private sub getcountry(ip) [br]if (countryflag=1 or countryflag=2) then [br]country=getflagstr(endipoff+4) [br]if countryflag=1 then [br]localstr=getflagstr(stream.position) [br]if ip>= ip2int("255.255.255.0") and ip<=ip2int("255.255.255.255") then [br]localstr=getflagstr(endipoff+21) [br]country=getflagstr(endipoff+12) [br]end if [br]else [br]localstr=getflagstr(endipoff+8) [br]end if [br]else [br]country=getflagstr(endipoff+4) [br]localstr=getflagstr(stream.position) [br]end if [br]country=trim(country) [br]localstr=trim(localstr) [br]if instr(country,"cz88.net") then country = "ialvin.cn" [br]if instr(localstr,"cz88.net") then localstr = "ialvin.cn" [br]end sub [br][br]private function getflagstr(offset) [br]dim flag [br]flag=0 [br]do while (true) [br]stream.position=offset [br]flag=ascb(stream.read(1)) [br]if(flag=1 or flag=2 ) then [br]buf=stream.read(3) [br]if (flag=2 ) then [br]countryflag=2 [br]endipoff=offset-4 [br]end if [br]offset=ascb(midb(buf,1,1))+(ascb(midb(buf,2,1))*256)+(ascb(midb(buf,3,1))*256*256) [br]else [br]exit do [br]end if [br]loop [br][br]if (offset<12 ) then [br]getflagstr="" [br]else [br]stream.position=offset [br]getflagstr=getstr() [br]end if [br]end function [br][br]private function getstr() [br]dim c [br]getstr="" [br]do while (true) [br]c=ascb(stream.read(1)) [br]if (c=0) then exit do [br][br]if c>127 then [br]if stream.eos then exit do [br]getstr=getstr&chr(ascw(chrb(ascb(stream.read(1)))&chrb(c))) [br]else [br]getstr=getstr&chr(c) [br]end if [br]loop [br]end function [br][br]public function qqwry(dotip) [br]dim ip,nret [br]dim rangb,range,recno [br]ip=ip2int(dotip) [br]set stream=createobject("adodb.stream") [br]stream.mode=3 [br]stream.type=1 [br]stream.open [br]stream.loadfromfile qqwryfile [br]stream.position=0 [br]buf=stream.read(8) [br]firststartip=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) [br]laststartip=ascb(midb(buf,5,1))+(ascb(midb(buf,6,1))*256)+(ascb(midb(buf,7,1))*256*256)+(ascb(midb(buf,8,1))*256*256*256) [br]recordcount=int((laststartip-firststartip)/7) [br]if (recordcount<=1) then [br]country="unknow" [br]qqwry=2 [br]exit function [br]end if [br]rangb=0 [br]range=recordcount [br]do while (rangb<(range-1)) [br]recno=int((rangb+range)/2) [br]call getstartip (recno) [br]if (ip=startip) then [br]rangb=recno [br]exit do [br]end if [br]if (ip>startip) then [br]rangb=recno [br]else [br]range=recno [br]end if [br]loop [br]call getstartip(rangb) [br]call getendip() [br]if (startip<=ip) and ( endip>=ip) then [br][br]nret=0 [br]else [br][br]nret=3 [br]end if [br]call getcountry(ip) [br]qqwry=nret [br]end function [br][br]private sub class_terminate() [br]on error resume next [br]stream.close [br]if err then err.clear [br]set stream=nothing [br]end sub [br]end class [br][br][br][br]function look_ip(path,ip) [br]dim wry, iptype, qqwryversion, ipcounter [br]set wry = new tqqwry [br]wry.setpath path [br]on error resume next [br]iptype = wry.qqwry(ip) [br]look_ip = wry.country & " - " & wry.localstr [br]if err then [br]err.clear [br]look_ip = "查询出错" [br]end if [br]end function [br]%>[br][br]下面是查询代码,请保存为search.asp [br] [br]<% [br]dim ip [br]ip=request.querystring("ip") [br][br]if trim(ip)="" then [br]ip=request.servervariables("remote_addr") [br]elseif ubound(split(trim(ip),"."))<>3 then [br]ip=request.servervariables("remote_addr") 'ip地址 [br]end if [br]ipadd=look_ip("cz.dat",ip) '这里注意,数据库文件名是cz.dat [br]response.write ipadd [br]%>

该文章在 2010/7/13 18:46:00 编辑过
关键字查询
相关文章
正在查询...
点晴ERP是一款针对中小制造业的专业生产管理软件系统,系统成熟度和易用性得到了国内大量中小企业的青睐。
点晴PMS码头管理系统主要针对港口码头集装箱与散货日常运作、调度、堆场、车队、财务费用、相关报表等业务管理,结合码头的业务特点,围绕调度、堆场作业而开发的。集技术的先进性、管理的有效性于一体,是物流码头及其他港口类企业的高效ERP管理信息系统。
点晴WMS仓储管理系统提供了货物产品管理,销售管理,采购管理,仓储管理,仓库管理,保质期管理,货位管理,库位管理,生产管理,WMS管理系统,标签打印,条形码,二维码管理,批号管理软件。
点晴免费OA是一款软件和通用服务都免费,不限功能、不限时间、不限用户的免费OA协同办公管理系统。
Copyright 2010-2024 ClickSun All Rights Reserved