请问谁能帮我写一个IP地址查询的ASP程序?原理思路我有,但是因为我不怎么会
ASP,所以希望有人能帮我写一个完整的,加我QQ:89164279,具体谈一下。我可以
给300-400分。谢谢!
---------------------------------------------------------------
我到有一个。只是判断的。不是查询的,但是你要有数据库的结合,有数据阿
我只能给我的代码给你参考一下乐
1
2if session("flag")="" then
3f_ip=request.servervariables("remote_addr")
4f_ip_list=split(f_ip,".")
5ip_sql="select s_ip,e_ip,id from t_ip order by id asc "
6set ip_rs=server.createobject("adodb.recordset")
7ip_rs.open ip_sql,conn,1
8flag=0
9do while not ip_rs.eof
10if trim(ip_rs("s_ip"))<>"" then s_ip_list=split(ip_rs("s_ip"),".")
11if trim(ip_rs("e_ip"))<>"" then e_ip_list=split(ip_rs("e_ip"),".")
12response.write ip_rs("e_ip")
13redim ipflag(4)
14for i=lbound(e_ip_list) to ubound(e_ip_list)
15if cint(f_ip_list(i))>=cint(s_ip_list(i)) and cint(f_ip_list(i))=
<cint(e_ip_list(i)) f_ip_list(i)&","&s_ip_list(i)&","&e_ip_list(i)&"<br="" response.write="" then="">"
ipflag(i)=1
else
ipFlag(i)=0
end if
next
response.write ipFlag(0)&"Ò»"&ipflag(1)&"¶þ"&ipflag(2)&"Èý"&ipflag(3)&"xxx"
if ipflag(0)=1 and ipflag(1)=1 and ipflag(2)=1 and ipflag(3)=1 then
flag=1
session("flag")=flag
exit do
else
flag=0
session("flag")=flag
end if
response.write flag
ip_rs.movenext
loop
session("flag")=flag
ip_rs.close
set ip_rs=nothing
end if
if session("flag")<>0 then
if indexPage<>1 then response.redirect "/main.asp"
end if
1\---------------------------------------------------------------
2
3http://www.hncj.com/book/list.asp?fl=1&id=303
4转...
5
6用ASP和wry.dll来制作全球IP地址查询系统
7
8
9
102002-11-7 飞翔网络
11
12用ASP和wry.dll来制作全球IP地址查询系统
13
14
15
16作者:kill
17
18
19用ASP和wry.dll来制作全球IP地址查询系统
20日期:[2002-6-7]
21
22突然在某某网站看到IP地址查询,于是心血来潮做了一个。这是用asp查询全球IP地址的程式,由于类似的的用Asp查询IP的速度不是很理想,本人使用的也是宏志宏的IP地址数据库,只是对它进行了改进。
23
24本人在 win98+pws+access2000上测试通过,效果比较理想。
25
26数据库的设计在一个软件中的比例,毫不夸张的说占60%,虽然这是一个小的程式,但也得到一定的体现。
27
28有任何错误或建议请一定要给我发E-mail: [email protected] ,我也不了解“追捕”等类似算法,欢迎交流,谢谢!
29
30好了废话少说,开始吧。
31
321、 转wry.dll为.mdb由于我们要优化数据库(适合我们用的),建议这样做:
33
34将文件改为wry.xls用Excel打开。
35
36在Access中新建表IP
37
38字段名 类型 长度 说明
39
40\---------------------------------------------------------------------------------------
41
42id 自动编号
43
44newid 数字 5 startip前三个数字
45
46seconded 数字 5 startip第二部分三个数字
47
48startip 文本 20 起始IP段
49
50endip 文本 20 止 IP 段
51
52country 文本 此段IP所在国家或省
53
54local 文本 此段IP所在地
55
56
57从Excel中copy startip/endip/country/local 四个字段至Access ,id会自动添加,对于newid和secondid当然我们不可能手工添加,可以这样实现。
58
59<!--#include file="dbpath.asp"-->
60
61
sqlcmd="select * from ip"
‘建议使用sqlcmd="select * from ipwhere id>=值1 and id<值2" ,因为对于一万个左右的数据一下子添加资源占用很大
set rs=ip.execute(sqlcmd)
do while not rs.eof
fir=left(rs("startip"),3)
sec=mid(rs("startip"),5,3)
sqlcmd3="update ip set newid=''"&str&"'',secondid=''"sec"'' "
ip.execute sqlcmd3
rs.movenext
loop
1
2这样就完成数据库的修改,对于dbpath.asp 文件下面讲
3
42、 文件介绍
5
6本程序分 dbpath.asp 和 search.asp
7
8以下是源程序及简要描述
9
10Dbpath.Asp 代码如下:(本人命名数据库名字为ip.mdb)
11
12
@ Language=VBScript
1
set ip=server.createobject("ADODB.CONNECTION")
ip.Open "driver={Microsoft Access Driver (*.mdb)};dbq=" & Server.MapPath("ip.mdb")
1
2
3search.asp 代码如下:
4
5<!--#include file="dbpath.asp"-->
6
'' Write by 尥蹶子
'' If you find some error or you have better idea
'' Please contact me
'' My Email: [email protected] Oicq:30763914
1
''建立一个提交的表单
1
2<body bgcolor="azure">
3<p align="center">IP查询<br/><br/><br/>
4<form action="index.asp" id="FORM1" method="post" name="FORM1">
5<font size="2">输入IP:</font><input id="text1" name="putip" style="BACKGROUND-COLOR: lavender; HEIGHT: 22px; WIDTH: 182px"/>
6<input id="submit1" name="sub1" style="BACKGROUND-COLOR: lightblue; FONT-SIZE: 12" tabindex="0" type="submit" value="我查"/>
7</form>
8
9
userip=Request.ServerVariables ("REMOTE_ADDR")
listip=trim(request("putip"))
if listip="" or listip=" " then
Response.Write "<p align="center"><font size="2">请输入IP地址!</font></p>"
else
''---判断访问者的IP是否与输入的ip同
cmp=strcomp(userip,listip,1)
if cmp=0 then
1
2<p align="center"><font size="2">这就是你自己呀!</font></p>
3
else
''获得输入ip的第1段,并置3位
num1=Instr(listip,".")
''判断第一段是否正确
if mun1=1 then
Response.Write "<p align="center">"&listip&"<br/>"&" <font size="2">非有效的IP地址,IP每段必须1~3位!</font></p>"
else
fir=left(listip,num1-1)
if len(fir)=2 then
fir=0&fir
end if
if len(fir)=1 then
fir=0&fir
fir=0&fir
end if
''获得输入ip的第2段,并置3位
num2=Instr(num1+1,listip,".")
sec=mid(listip,num1+1,num2-(num1+1))
if len(sec)=2 then
sec=0&sec
end if
if len(sec)=1 then
sec=0&sec
sec=0&sec
end if
''获得输入ip的第3段,并置3位
num3=Instr(num2+1,listip,".")
thr=mid(listip,num2+1,num3-(num2+1))
if len(thr)=2 then
thr=0&thr
end if
if len(thr)=1 then
thr=0&thr
thr=0&thr
end if
''获得输入ip的第4段,并置3位
fou=right(listip,len(listip)-num3)
if len(fou)=2 then
fou=0&fou
end if
if len(fou)=1 then
fou=0&fou
fou=0&fou
end if
''判断是否为有效IP
if len(fir)=0 or len(fir)>3 or len(sec)=0 or len(sec)>3 or len(thr)=0 or len(thr)>3 or len(fou)=0 or len(fou)>3 then
Response.Write "<p align="center">"&listip&"<br/>"&" <font size="2">非有效的IP地址,IP每段必须1~3位!</font></p>"
else
''判断是否为保留地址
if ((fir>=0) and (fir<= 2)) or ((fir>=58) and (fir<=60)) or ((fir>=67) and (fir<=126)) then
Response.Write "<p align="center">"&listip&"<br/>"&" <font size="2">Internet IP保留地址!</font></p>"
else
''判断是否为分配地址
if (fir>=219 and fir<=223) or fir=225 then
Response.Write "<p align="center">"&listip&"<br/>"&" <font size="2">此IP地址尚未分配!</font></p>"
else
if fir>255 or fir<0 or sec>255 or sec<0 or thr>255 or thr<0 or fou>255 or fou<0 then
Response.Write "<p align="center">"&listip&"<br/>"&" <font size="2">Internet IP地址输入值不正确!</font></p>"
else
''查询IP地址数据库
Set sql= Server.CreateObject("ADODB.Recordset")
rs1="select id,startip,endip,country,local from ip where id<9904 and newid="&fir&" and secondid="&sec&" "
sql.open rs1,ip,1,1
''对于类似224.000.000.000~224.255.255.255的ip地址进行处理
if sql.RecordCount = 1 then
sql.Close
sqlcmd2="select id,startip,endip,country,local from ip where id<9904 and newid="&fir&" and secondid="&sec&" order by id desc"
set rs=ip.execute(sqlcmd2)
else
sqlcmd2="select id,startip,endip,country,local from ip where id<9904 and newid="&fir&" order by id desc"
set rs=ip.execute(sqlcmd2)
if rs.eof then
1
2<br/><br/><font size="2"><p align="center">```
3=listip
4```<br/>★未知IP数据★<br/>如果你知道请告诉我!OICQ:30763914 谢谢!<br/>=尥蹶子=</p></font></p>
5
6<% else
7
8do while not rs.eof
9
10''*******处理country or local为空的情况,使用了按id倒排(why?因为根据IP地址表可知,先列大地区的ip段,例如先列出欧洲的062.000.000.000~062.255.255.255,再列英国等IP段)
11
12''对后面三段IP进行处理,是否在IP表内
13
14if (sec>=(mid(rs("startip"),5,3)) and (sec<=mid(rs("endip"),5,3))) and (thr>=(mid(rs("startip"),9,3)) and (thr<=mid(rs("endip"),9,3))) and (fou>=(mid(rs("st</body></cint(e_ip_list(i))>