欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  IT编程

根据IP地址自动判断转向分站的代码

程序员文章站 2022-06-13 18:37:20
function getipvalue(clientip)  得到客户端 的ip转换成长整型,返回值getipvalueon error resume nextdim strip, arr...

function getipvalue(clientip)  得到客户端 的ip转换成长整型,返回值getipvalue
on error resume next
dim strip, array_ip
strip=0
array_ip = split(clientip,".")
if ubound(array_ip)<>3 then
getipvalue=0
exit function
end if
for i=0 to 3
strip=strip+(cint(array_ip(i))*(256^(3-i)))
next
getipvalue=strip
if err then getipvalue=0
end function

 

  clientip=request.servervariables("remote_host")
ipvalue=getipvalue(clientip)

strsql="select top 1 city from [ipaddress]  where "&ipvalue&" between ip1 and ip2"
set rsip=conn.execute(strsql)
if rsip.bof and rsip.eof then
urlcity="未知"
else
urlcity=rsip.fields.item("city").value
end if

         if instr(urlcity,"广州")<>0 then response.redirect("https://code.rdxx.com")
        if instr(urlcity,"深圳")<>0 then response.redirect("https://moban.rdxx.com")
        if instr(urlcity,"上海")<>0 then response.redirect("https://font.rdxx.com")

由于ip库超过1m,所以上传不了,ip库网上很多。上面只是其中一种方法.