我的目标是获取IP,判断是北京的IP的话,就进入一个页
怎么写呀?
if Request.ServerVariables("REMOTE_ADDR") 是北京段 then
这里涉及到北京的IP段的数据库。
高分友情大家予以协助。
编程:获取IP,判断是否为北京的IP
答案:4 悬赏:60 手机版
解决时间 2021-05-04 11:54
- 提问者网友:末路
- 2021-05-04 07:52
最佳答案
- 五星知识达人网友:几近狂妄
- 2021-05-04 08:02
<%
Function lookaddress(sip)
Dim str1, str2, str3, str4
Dim num
Dim irs
If IsNumeric(Left(sip, 2)) Then
If sip = "127.0.0.1" Then sip = "192.168.0.1"
str1 = Left(sip, InStr(sip, ".") - 1)
sip = Mid(sip, InStr(sip, ".") + 1)
str2 = Left(sip, InStr(sip, ".") - 1)
sip = Mid(sip, InStr(sip, ".") + 1)
str3 = Left(sip, InStr(sip, ".") - 1)
str4 = Mid(sip, InStr(sip, ".") + 1)
If IsNumeric(str1) = 0 Or IsNumeric(str2) = 0 Or IsNumeric(str3) = 0 Or IsNumeric(str4) = 0 Then
Else
num = cdbl(str1) * 16777216 + cdbl(str2) * 65536 + cdbl(str3) * 256 + cdbl(str4) - 1
sql = "select timezone from IPaddress where startip <=" & num & " and endip >=" & num
Set irs = conn.Execute(sql)
If irs.EOF And irs.BOF Then
lookaddress = "0"
Else
Do While Not irs.EOF
lookaddress = irs(0)
irs.MoveNext
Loop
End If
irs.Close
Set irs = Nothing
End If
Else
lookaddress = "0"
End If
End Function
userip = Request.ServerVariables("HTTP_X_FORWARDED_FOR")
If userip = "" Then userip = Request.ServerVariables("REMOTE_ADDR")
visitflag = lookaddress(userip)
if visitflag = "" then
Response.Write("window.location.href=' http:/www.goimage.cn';")
elseif visitflag="010"
Response.Write("window.location.href='http:/bj.goimage.cn';")
end if
%>
数据库结构:
表名:IPaddress
startip: 起始IP
endip: 结束IP
country: 所在位置
timezone: 电话区号(这里根据电话区号做判断,分站可以做到县级)
Function lookaddress(sip)
Dim str1, str2, str3, str4
Dim num
Dim irs
If IsNumeric(Left(sip, 2)) Then
If sip = "127.0.0.1" Then sip = "192.168.0.1"
str1 = Left(sip, InStr(sip, ".") - 1)
sip = Mid(sip, InStr(sip, ".") + 1)
str2 = Left(sip, InStr(sip, ".") - 1)
sip = Mid(sip, InStr(sip, ".") + 1)
str3 = Left(sip, InStr(sip, ".") - 1)
str4 = Mid(sip, InStr(sip, ".") + 1)
If IsNumeric(str1) = 0 Or IsNumeric(str2) = 0 Or IsNumeric(str3) = 0 Or IsNumeric(str4) = 0 Then
Else
num = cdbl(str1) * 16777216 + cdbl(str2) * 65536 + cdbl(str3) * 256 + cdbl(str4) - 1
sql = "select timezone from IPaddress where startip <=" & num & " and endip >=" & num
Set irs = conn.Execute(sql)
If irs.EOF And irs.BOF Then
lookaddress = "0"
Else
Do While Not irs.EOF
lookaddress = irs(0)
irs.MoveNext
Loop
End If
irs.Close
Set irs = Nothing
End If
Else
lookaddress = "0"
End If
End Function
userip = Request.ServerVariables("HTTP_X_FORWARDED_FOR")
If userip = "" Then userip = Request.ServerVariables("REMOTE_ADDR")
visitflag = lookaddress(userip)
if visitflag = "" then
Response.Write("window.location.href=' http:/www.goimage.cn';")
elseif visitflag="010"
Response.Write("window.location.href='http:/bj.goimage.cn';")
end if
%>
数据库结构:
表名:IPaddress
startip: 起始IP
endip: 结束IP
country: 所在位置
timezone: 电话区号(这里根据电话区号做判断,分站可以做到县级)
全部回答
- 1楼网友:像个废品
- 2021-05-04 09:33
using System.Net; IPAddress addr = new IPAddress(Dns.GetHostByName(Dns.GetHostName()).AddressList[0].Address); string newIP= addr.ToString();//首先获得本地IP
if(newIP==北京IP)
{
ClientScript.RegisterStartupScript(typeof(string), "", "<script>alert('IP相同,跳转页面');href='newpage.aspx'</script>");
}
else
{
ClientScript.RegisterStartupScript(typeof(string), "", "<script>alert('IP不是北京的IP')</script>");
}
- 2楼网友:等灯
- 2021-05-04 08:59
1、先把北京的所有IP记录在数据库中
2、程序获取客户端的IP,同数据库中对比,要用循环或者in
- 3楼网友:不甚了了
- 2021-05-04 08:40
自己有数据库查询
或者利用网络 从别人的网站上查 获取结果 显示在你那
我要举报
如以上问答信息为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
大家都在看
推荐资讯