Function Fn_GetIPAddr(Ipaddr)
'根据IP地址得到所在地区
dim tmpSQL,rs,tmpIpAddr
dim str1,str2,str3,str4,num
If isnumeric(left(Ipaddr,2)) Then
If Ipaddr="127.0.0.1" Then Ipaddr="192.168.0.1"
str1=left(Ipaddr,instr(Ipaddr,".")-1)
Ipaddr=mid(Ipaddr,instr(Ipaddr,".")+1)
str2=left(Ipaddr,instr(Ipaddr,".")-1)
Ipaddr=mid(Ipaddr,instr(Ipaddr,".")+1)
str3=left(Ipaddr,instr(Ipaddr,".")-1)
str4=mid(Ipaddr,instr(Ipaddr,".")+1)
If isNumeric(str1)=0 Or isNumeric(str2)=0 Or isNumeric(str3)=0 Or isNumeric(str4)=0 Then
Else
num=cint(str1)*256*256*256+cint(str2)*256*256+cint(str3)*256+cint(str4)-1
tmpSQL = "select top 1 Country from ipdata where StartIP <='"&num&"' and EndIP >='"&num&"'"
'Response.Write(tmpSQL)
set rs = conn.execute(tmpSQL)
if rs.bof and rs.eof then
Fn_GetIPAddr = "未知地址"
else
Fn_GetIPAddr = rs("Country")
end if
'end if
end if
Else
Fn_GetIPAddr = "无效IP"
End If
End Function
取IP地址
Ipaddr = Request.ServerVariables("HTTP_X_FORWARDED_FOR")
If Ipaddr = "" Then
Ipaddr = Request.ServerVariables("REMOTE_ADDR")
end if
取地区要根据IP数据库查了