ASP程序查看IP来源
查询IP地址的方法Google一下多的是,但是客户需要的并不是二次Google的结果,往往一个链接单击过后出现的结果会更让客户满意!
总结网络所传与实践得到如下ASP代码:
<%
functionGetSourceInfo(byvalurl,ByValipstr)'这里处理POST传递参数
Setxmlhttp=CreateObject("Msxml2.ServerXMLHTTP")
strA="ip="&ipstr&"&action=2"
Withxmlhttp
.Open"POST",url,False
.setRequestHeader"Content-Length",len(strA)
.setRequestHeader"CONTENT-TYPE","application/x-www-form-urlencoded"
.SendstrA
if.status<>200then
xmlget="error"
else
xmlget=bin2str(.responseBody)
endif
EndWith
setxmlhttp=nothing
GetSourceInfo=xmlget
endFunction
Functionbin2str(ByValbinstr)
ConstadTypeBinary=1
ConstadTypeText=2
DimBytesStream,StringReturn
SetBytesStream=Server.CreateObject("ADODB.Stream")'建立一个流对象
WithBytesStream
.Type=adTypeText
.Open
.WriteTextbinstr
.Position=0
.Charset="GB2312"
.Position=2
StringReturn=.ReadText
.close
EndWith
SetBytesStream=Nothing
bin2str=StringReturn
EndFunction
FunctionGetBody(ConStr,StartStr,OverStr,IncluL,IncluR)'这里用来传递字符
IfConStr="$False$"orConStr=""orIsNull(ConStr)=TrueOrStartStr=""orIsNull(StartStr)=TrueOrOverStr=""orIsNull(OverStr)=TrueThen
GetBody="$False$"
ExitFunction
EndIf
ConStrTemp=Lcase(ConStr)
StartStr=Lcase(StartStr)
OverStr=Lcase(OverStr)
Start=InStrB(1,ConStrTemp,StartStr,vbBinaryCompare)
IfStart<=0then
GetBody="$False$"
ExitFunction
Else
IfIncluL=FalseThen
Start=Start+LenB(StartStr)
EndIf
EndIf
Over=InStrB(Start,ConStrTemp,OverStr,vbBinaryCompare)
IfOver<=0OrOver<=Startthen
GetBody="$False$"
ExitFunction
Else
IfIncluR=TrueThen
Over=Over+LenB(OverStr)
EndIf
EndIf
GetBody=MidB(ConStr,Start,Over-Start)
EndFunction
%>
<tablewidth="768"border="0"align="center"cellpadding="4"cellspacing="6">
<tr>
<tdwidth="100%"align="center"valign="top"bgcolor="#FFFFFF">
<%
ipdata=Request("ipdata")
Ifipdata=EmptyThen
%>
<tableborder="0"align="center"cellpadding="0"cellspacing="1">
<FORMMETHOD=POSTACTION="ip.asp"name="form"target="_blank">
<tr>
<tdalign="center">
<h1>查询IP地址:</h1>
<inputtype="text"name="ipdata"size="16">
<inputtype="submit"value="查询">
<inputtype="hidden"name="action"value="2">
</td>
</tr>
</FORM>
</table>
<br>
<%Else
response.write"<h1>查询的IP归属地"
'response.write(GetBody(GetSourceInfo("http://www.ip138.com/ips8.asp",ipdata),"<h1>您查询的IP","</li></ul></td>",False,False))
response.write(GetBody(GetSourceInfo("http://www.ip138.com/ips8.asp",ipdata),"<h1>您查询的IP","</li></ul><center>",False,False))'IP138最近的查询结果页特征码
response.write"</li></ul>"
EndIf%>
<br>
数据来自www.IP138.com
</td>
</tr>
</table>
查询IP地址的方法Google一下多的是,但是客户需要的并不是二次Google的结果,往往一个链接单击过后出现的结果会更让客户满意!
总结网络所传与实践得到如下ASP代码:
<%
functionGetSourceInfo(byvalurl,ByValipstr)'这里处理POST传递参数
Setxmlhttp=CreateObject("Msxml2.ServerXMLHTTP")
strA="ip="&ipstr&"&action=2"
Withxmlhttp
.Open"POST",url,False
.setRequestHeader"Content-Length",len(strA)
.setRequestHeader"CONTENT-TYPE","application/x-www-form-urlencoded"
.SendstrA
if.status<>200then
xmlget="error"
else
xmlget=bin2str(.responseBody)
endif
EndWith
setxmlhttp=nothing
GetSourceInfo=xmlget
endFunction
Functionbin2str(ByValbinstr)
ConstadTypeBinary=1
ConstadTypeText=2
DimBytesStream,StringReturn
SetBytesStream=Server.CreateObject("ADODB.Stream")'建立一个流对象
WithBytesStream
.Type=adTypeText
.Open
.WriteTextbinstr
.Position=0
.Charset="GB2312"
.Position=2
StringReturn=.ReadText
.close
EndWith
SetBytesStream=Nothing
bin2str=StringReturn
EndFunction
FunctionGetBody(ConStr,StartStr,OverStr,IncluL,IncluR)'这里用来传递字符
IfConStr="$False$"orConStr=""orIsNull(ConStr)=TrueOrStartStr=""orIsNull(StartStr)=TrueOrOverStr=""orIsNull(OverStr)=TrueThen
GetBody="$False$"
ExitFunction
EndIf
ConStrTemp=Lcase(ConStr)
StartStr=Lcase(StartStr)
OverStr=Lcase(OverStr)
Start=InStrB(1,ConStrTemp,StartStr,vbBinaryCompare)
IfStart<=0then
GetBody="$False$"
ExitFunction
Else
IfIncluL=FalseThen
Start=Start+LenB(StartStr)
EndIf
EndIf
Over=InStrB(Start,ConStrTemp,OverStr,vbBinaryCompare)
IfOver<=0OrOver<=Startthen
GetBody="$False$"
ExitFunction
Else
IfIncluR=TrueThen
Over=Over+LenB(OverStr)
EndIf
EndIf
GetBody=MidB(ConStr,Start,Over-Start)
EndFunction
%>
<tablewidth="768"border="0"align="center"cellpadding="4"cellspacing="6">
<tr>
<tdwidth="100%"align="center"valign="top"bgcolor="#FFFFFF">
<%
ipdata=Request("ipdata")
Ifipdata=EmptyThen
%>
<tableborder="0"align="center"cellpadding="0"cellspacing="1">
<FORMMETHOD=POSTACTION="ip.asp"name="form"target="_blank">
<tr>
<tdalign="center">
<h1>查询IP地址:</h1>
<inputtype="text"name="ipdata"size="16">
<inputtype="submit"value="查询">
<inputtype="hidden"name="action"value="2">
</td>
</tr>
</FORM>
</table>
<br>
<%Else
response.write"<h1>查询的IP归属地"
'response.write(GetBody(GetSourceInfo("http://www.ip138.com/ips8.asp",ipdata),"<h1>您查询的IP","</li></ul></td>",False,False))
response.write(GetBody(GetSourceInfo("http://www.ip138.com/ips8.asp",ipdata),"<h1>您查询的IP","</li></ul><center>",False,False))'IP138最近的查询结果页特征码
response.write"</li></ul>"
EndIf%>
<br>
数据来自www.IP138.com
</td>
</tr>
</table>