求助,根据淘宝ip库进行跳转的asp代码

okoma 2014-08-26 04:08:21
根据淘宝ip库,判断用户ip是否是 上海 如果不是上海进行跳转,如果是上海则不跳转!

淘宝ip库地址是ip点淘宝点com
...全文
362 4 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
csdn_aspnet 2014-08-28
  • 打赏
  • 举报
回复
现在根据下面代码已经可以实现根据判断内网外网IP跳转到不同页面 比如外面就直接跳到2.htm,内网就直接跳1.htm <% ipx=Request.ServerVariables("HTTP_X_FORWARDED_FOR") IF ipx="" Then ipx=Request.ServerVariables("REMOTE_ADDR") if ipcheck(ipx,"202.116.192.1","202.116.250.254")="true" then response.Redirect "1.htm" elseif ipcheck(ipx,"172.16.0.1","172.16.255.254 ")="true" then response.Redirect "1.htm" elseif ipcheck(ipx,"192.168.0.1","192.168.255.254 ")="true" then response.Redirect "1.htm" else response.Redirect "2.htm" end if function ipcheck(ip,startIp,endIp) ipPart=split(ip,".") startIpPart =split(startIp,".") endIpPart =split(endIp,".") if ipPart(0)&"."&ipPart(1)=startIpPart(0)&"."&startIpPart(1) then if ipPart(2)>=startIpPart(2) and ipPart(2)<=endIpPart(2) then ipcheck="true" else ipcheck="false" end if else ipcheck="false" end if end function %> 但是外网知道1.HTM这地址直接打地址就可以访问的. 怎样在1.htm做限制呢??如果他是外网打1.htm这个地址还是要他跳会2.htm这个页面呢? ipx=Request.ServerVariables("HTTP_X_FORWARDED_FOR") IF ipx="" Then ipx=Request.ServerVariables("REMOTE_ADDR") if not(ipCheck(ipx,"202.116.192.1","202.116.250.254") or ipCheck(ipx,"202.116.192.1","202.116.250.254") or ipcheck(ipx,"202.116.192.1","202.116.250.254")) then response.redirect("2.html") 不过在IIS里要设置默认访问页面,把默认页面指向上面的代码页面。
文盲老顾 2014-08-27
  • 打赏
  • 举报
回复
使用#2的部分代码

Response.CharSet = "utf-8"
ip="114.80.166.240"
html=getHTML(ip)
html = unescape(Replace(html,"\","%"))
if instr(html,"上海") then
else
end if
  • 打赏
  • 举报
回复
xmlhttp下载淘宝的地址,然后判断返回值是否包含上海,不过返回的内容是unicode编码过的,不能直接判断上海,判断上海的unicode编码"\u4e0a\u6d77\u5e02"
Function getHTML(ip)
  dim xhr,url
  url="http://ip.taobao.com/service/getIpInfo.php?ip="&ip
  set xhr=createobject("MSXML2.XMLHTTP")
  xhr.open "GET",url,false
  xhr.send()
  If xhr.readystate<>4 then
    exit function
  End If
  getHTML=getText(xhr.responseBody)
  set xhr=nothing
  if err.number<>0 then err.Clear
End Function
Function getText(body)
  dim ado
  set ado = CreateObject("adodb.stream")
  ado.Type = 1
  ado.Mode =3
  ado.Open
  ado.Write body
  ado.Position = 0
  ado.Type = 2
  ado.Charset = "gb2312"
  getText = ado.ReadText
  ado.Close
  set ado = nothing
end Function

ip="114.80.166.240"
html=getHTML(ip)
response.Write ip&":"
if instr(html,"""city"":""\u4e0a\u6d77\u5e02""")<>0 then
  response.Write "上海市ip"
else
  response.Write "不是上海市ip"
end if
response.Write "<br>"
ip="121.52.209.112"
html=getHTML(ip)
response.Write ip&":"
if instr(html,"""city"":""\u4e0a\u6d77\u5e02""")<>0 then
  response.Write "上海市ip"
else
  response.Write "不是上海市ip"
end if
宁静志远 2014-08-27
  • 打赏
  • 举报
回复
淘宝ip接口返回的数据是json的,用jquery进行解析返回的json数据然后判断跳转更方便点,asp需要自己另外写解析json的方法或网上下个asp解析json的类来做

28,409

社区成员

发帖
与我相关
我的任务
社区描述
ASP即Active Server Pages,是Microsoft公司开发的服务器端脚本环境。
社区管理员
  • ASP
  • 无·法
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧