获取客户地理地址的ASP代码

来源:互联网 发布:dalo流控源码 编辑:程序博客网 时间:2024/04/30 04:56

<%
function GetResStr(URL,code)
err.clear
dim ResBody,ResStr,PageCode,ReturnStr
Set Http=server.createobject("Microsoft.XMLHTTP")
Http.open "GET",URL,False
Http.Send()
If Http.Readystate =4 Then
  If Http.status=200 Then
    ResBody=http.responseBody
    ReturnStr=BytesToBstr(http.responseBody,code)
    GetResStr=ReturnStr
  End If
End If
End Function

'函数名:BytesToBstr
'作用:转换二进制数据为字符
'参数:Body-二进制数据,Cset-文本编码方式
Function BytesToBstr(Body,Cset)
  Dim Objstream
  Set Objstream = Server.CreateObject("adodb.stream")
  objstream.Type = 1
  objstream.Mode =3
  objstream.Open
  objstream.Write body
  objstream.Position = 0
  objstream.Type = 2
  objstream.Charset =Cset
  BytesToBstr = objstream.ReadText
  objstream.Close
  set objstream = nothing
End Function

dim reg,vUrl,VBody,code,time1,time2,title
vUrl="http://www.ip138.com/ips.asp?ip="&request.servervariables("REMOTE_ADDR")
TempStr=GetResStr(vUrl,"gb2312")
p1=instr(TempStr,"""")+1
p2=InStrRev(TempStr,"""")
Add=mid(TempStr,p1,p2-p1)

'自己的替换,截取地理地址
'shu=instr(TempStr,"参考数据二:")
'response.write shu
'response.end

dizhi1=split(TempStr,"参考数据二:")
dizhi2=split(dizhi1(1)," ")
dizhi3=dizhi2(0)

response.write "您的IP为:"&request.servervariables("REMOTE_ADDR")&"<br />"
response.write "您的位置:"&dizhi3&"<br />"
%> 

原创粉丝点击