日期:2014-05-16 浏览次数:20521 次
<% '得到访问者IP public Function getip() Dim strIPAddr If Request.ServerVariables("HTTP_X_FORWARDED_FOR") = "" OR InStr(Request.ServerVariables("HTTP_X_FORWARDED_FOR"), "unknown") > 0 Then strIPAddr = Request.ServerVariables("REMOTE_ADDR") ElseIf InStr(Request.ServerVariables("HTTP_X_FORWARDED_FOR"), ",") > 0 Then strIPAddr = Mid(Request.ServerVariables("HTTP_X_FORWARDED_FOR"), 1, InStr(Request.ServerVariables("HTTP_X_FORWARDED_FOR"), ",")-1) actforip=Request.ServerVariables("REMOTE_ADDR") ElseIf InStr(Request.ServerVariables("HTTP_X_FORWARDED_FOR"), ";") > 0 Then strIPAddr = Mid(Request.ServerVariables("HTTP_X_FORWARDED_FOR"), 1, InStr(Request.ServerVariables("HTTP_X_FORWARDED_FOR"), ";")-1) actforip=Request.ServerVariables("REMOTE_ADDR") Else strIPAddr = Request.ServerVariables("HTTP_X_FORWARDED_FOR") actforip=Request.ServerVariables("REMOTE_ADDR") End If getip = Trim(Mid(strIPAddr, 1, 30)) End Function ' ============================================ ' 返回IP地区信息 ' ============================================ Function Look_Ip(IP) Dim Wry, IPType, QQWryVersion, IpCounter ' 设置类对象 Set Wry = New TQQWry ' 开始搜索,并返回搜索结果 ' 您可以根据 QQWry(IP) 返回值来判断该IP地址在数据库中是否存在,如果不存在可以执行其他的一些操作 ' 比如您自建一个数据库作为追捕等,这里我就不详细说明了 IPType = Wry.QQWry(IP) ' Country:国家地区字段 ' LocalStr:省市及其他信息字段 Look_Ip = Wry.Country & " " & Wry.LocalStr End Function ' ============================================ ' 返回QQWry信息 ' ============================================ Function WryInfo() Dim Wry, IPType, QQWry(1) ' 设置类对象 Set Wry = New TQQWry IPType = Wry.QQWry("255.255.255.255") ' 读取数据库版本信息 QQWry(0) = Wry.Country & " " & Wry.LocalStr ' 读取数据库IP地址数目 QQWry(1) = Wry.RecordCount + 1 WryInfo = QQWry End Function ' ============================================ ' IP物理定位搜索类 ' ============================================ Class TQQWry ' ============================================ ' 变量声名 ' ============================================ Dim Country, LocalStr, Buf, OffSet Private StartIP, EndIP, CountryFlag Public QQWryFile Public FirstStartIP, LastStartIP, RecordCount Private Stream, EndIPOff ' ============================================ ' 类模块初始化 ' ============================================ Private Sub Class_Initialize Country = "" LocalStr = "" StartIP = 0 EndIP = 0 CountryFlag = 0 FirstStartIP = 0 LastStartIP = 0 EndIPOff = 0 QQWryFile = Server.MapPath("/yxgame/date/qqwry.dat") 'QQ IP库路径,要转换成物理路径 End Sub ' ============================================ ' IP地址转换成整数 ip ' ============================================ Function IPToInt(IP) If Instr(IP,":")>0 Then IP="127.0.0.1" '当IP地址是::1这样的地址时返回本机地址 Dim IPArray, i IPArray = Split(IP, ".", -1) FOr i = 0 to 3 If Not IsNumeric(IPArray(i)) Then IPArray(i) = 0 If CInt(IPArray(i)) < 0 Then IPArray(i) = Abs(CInt(IPArray(i))) If CInt(IPArray(i)) > 255 Then IPArray(i) = 255 Next IPToInt = (CInt(IPArray(0))*256*256*256) + (CInt(IPArray(1))*256*256) + (CInt(IPArray(2))*256) + CInt(IPArray(3)) End Function ' ============================================ ' 整数逆转IP地址 ' ===========