当前位置:K88软件开发文章中心编程语言AspAsp01 → 文章内容

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

减小字体 增大字体 作者:佚名     来源:asp编程网  发布时间:2018-12-30 8:30:37

为了让客户端更快速的访问网站,通常一个大型网站会有许多分站,所以让客户端访问相应的分站,会让客户有更好的体验,这就要用到根据客户端IP地址转向不同的分站。这里面要用到IP数据库,可到网上去下载。IP数据库在此主要用途是根据得到的IP,找到此IP所在的地址。
Function 
getIpvalue(clientIP)&
#39
得到客户端的IP转换成长整型,返回值getIpvalue
On 
Error 
Resume 
Next
Dim 
strIp, 
array_Ip
strIp=0
array_Ip 

Split(clientIP,"
."
)
If 
UBound(array_Ip)<
>

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 

City 
from 
[Ipaddress] 
where 
"
&

#38
IpValue&

#38
"
 

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,"
广州"
)<
>

then 

 
 
 
response.Redirect("
http://code.knowsky.com"
)
end 
if
if 
instr(UrlCity,"
深圳"
)<
>

then 

 
 
 
response.Redirect("
http://moban.knowsky.com"
)
end 
if
if 
instr(UrlCity,"
上海"
)<
>

then 

 
 
 
response.Redirect("
http://font.knowsky.com"
)
end 
if



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