web发布IIS日志代码
作者: Corbie 日期: 2008-07-02 13:19
1.数据库连接代码
2.主页代码
3.读取纯真IP数据库代码
下载: conn.asp
- <%
- dim startime
- dim conn
- dim connstr
- dim db,pass_word,User_ID,Data_Source
- startime=timer()
- db="" '数据库名称
- Pass_word="" 'Password=帐号密码
- User_ID="sa" 'User ID=登陆帐号
- Data_Source="localhost" 'Data Source=服务名称或者ip
- Set conn = Server.CreateObject("ADODB.Connection")
- connStr="Provider=SQLOLEDB.1;Password='"&pass_word&"';Persist Security Info=True;User ID='"&User_ID&"';Initial Catalog='"&db&"';Data Source='"&Data_Source&"'"
- conn.Open connstr
- function CloseDb
- Conn.close
- Set conn = Nothing
- End Function
- %>
2.主页代码
下载: index.asp
- <!--#include file=conn.asp-->
- <!--#include file=ip.asp-->
- <!--#include file=Neeao_SqlIn.Asp-->
- <%
- Dim rs,sql
- set rs=Server.CreateObject("ADODB.RecordSet")
- sql = "select top 2000 * from inetlog ORDER BY logtime DESC"
- rs.open sql,conn,3
- rs.pagesize=50
- if request("page")<>"" then
- epage=cint(request("page"))
- if epage<1 then epage=1
- if epage>rs.pagecount then epage=rs.pagecount
- else
- epage=1
- end if
- rs.absolutepage=epage
- 'response.write "("&rs("ClientHost")&")"
- 'response.write "("&rs("LogTime")&")"
- 'response.write "("&rs("service")&")"
- 'response.write "("&rs("serverip")&")"
- 'response.write "("&rs("processingtime")&")"
- 'response.write "("&rs("bytesrecvd")&")"
- 'response.write "("&rs("servicestatus")&")"
- 'response.write "("&rs("win32status")&")"
- 'response.write "("&rs("operation")&")"
- 'response.write "("&rs("target")&")"
- 'response.write "("&rs("parameters")&")"
- 'ip=rs("ClientHost")
- %>
- <style type="text/css">
- <!--
- .STYLE2 {color: #FF0000}
- .STYLE3 {color: #003399}
- .STYLE4 {
- color: #FF0000;
- font-family: "宋体";
- font-size: 24px;
- }
- .STYLE5 {color: #FF0000; font-family: "宋体"; font-size: 14px; }
- .STYLE6 {color: #009933}
- -->
- </style>
- <title>Nod32升级服务器信息</title>
- <p> </p>
- <p align="center" class="STYLE6"> </p>
- <table width="362" border="0" align="center">
- <tr>
- <td width="356"><div align="center"><span class="STYLE4">Nod32升级服务器即时信息统计表</span></div></td>
- </tr>
- </table>
- <table width="300" border="0" align="center">
- <tr>
- <td width="294"><div align="center" class="STYLE5">由于数据比较庞大,本站只提供部分升级信息</div></td>
- </tr>
- </table>
- <p align="center"><span class="STYLE6">
- <%
- IP = request("IP")
- If IP = "" then
- IP = Request.ServerVariables("REMOTE_ADDR")
- %>
- 嗨!你的IP是:<%=IP%>,来自<%=Disp_IPAddressData(IP,2)%><%=Disp_IPAddressData(IP,3)%>的朋友,i will intoyourbody now!
- <%else%>
- <%End if%>
- </span></p>
- <p align="center">服务器线路:安徽电信</p>
- <p align="center"> 升级服务器信息I: <a href="http://corbie.2288.org">http://corbie.2288.org</a> 服务器状态:<span class="STYLE2">在线</span></p>
- <p align="center"> 升级服务器信息II:<a href="http://eset.sifish.com.cn">http://eset.sifish.com.cn</a> 服务器状态:<span class="STYLE2">在线</span></p>
- <table width="87%" border="0" align="center" cellpadding="0" cellspacing="1" bgcolor="#0000FF">
- <tr bgcolor="#FFFFFF" align="center">
- <th width="15%"><span class="STYLE2">客户端ip</span></th>
- <th width="14%"><span class="STYLE2">客户端详细地址</span></th>
- <th width="23%"><span class="STYLE2">访问时间</span></th>
- <th width="17%"><span class="STYLE2">请求方式</span></th>
- <th width="15%"><span class="STYLE2">请求文件</span></th>
- <th width="16%"><span class="STYLE2">已读取字节</span></th>
- <th width="16%"><span class="STYLE2">状态</span></th>
- </tr>
- <%
- for i=0 to rs.pagesize-1
- if rs.bof or rs.eof then exit For
- ip=rs("ClientHost")
- %>
- <tr bgcolor="#FFFFFF" align="center">
- <th width="15%"><span class="STYLE3"><%=rs("ClientHost")%></span></th>
- <th width="14%"><span class="STYLE3"><%=Disp_IPAddressData(IP,2)%><%=Disp_IPAddressData(IP,3)%></th>
- <th width="23%"><span class="STYLE3"><%=rs("LogTime")%></span></th>
- <th width="17%"><span class="STYLE3"><%=rs("operation")%></span></th>
- <th width="15%"><span class="STYLE3"><%=rs("target")%></span></th>
- <th width="16%"><span class="STYLE3"><%=rs("bytessent")%></span></th>
- <th width="16%"><span class="STYLE3"><%=rs("servicestatus")%></span></th>
- </tr>
- <%
- rs.movenext()
- next
- %>
- <%
- for i=0 to rs.pagesize-1
- if rs.bof or rs.eof then exit For
- ip=rs("ClientHost")
- %>
- <%
- rs.movenext()
- next
- %>
- </table>
- <p align="center"> <a href="">首页</a> <a href="index.asp?page=<%=epage-1%>">前一页</a> <a href="index.asp?page=<%=epage+1%>">后一页</a> <a href="index.asp?page=<%=rs.pagecount%>">末页</a> </p>
- <p align="center">现在是第<%=epage%>页一共有<%=rs.pagecount%>页</p>
- <%
- conn.close()
- %>
- <p> </p>
3.读取纯真IP数据库代码
下载: ip.asp
- <%
- ' ============================================
- ' 返回IP信息 Disp_IPAddressData(IP,0)
- ' ============================================
- 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
- '''''Look_Ip = Wry.Country & ""
- End Function
- ' ============================================
- ' 返回IP信息 JS调用
- ' ============================================
- Function Disp_IPAddressData(IP, sType)
- Dim Wry, IPType
- Set Wry = New TQQWry
- IPType = Wry.QQWry(IP)
- Select Case sType
- Case 1 Disp_IPAddressData = IP
- Case 2 Disp_IPAddressData = Wry.Country
- Case 3 Disp_IPAddressData = Wry.LocalStr
- 'Case Else Disp_IPAddressData = Wry.Country & "" & Wry.LocalStr
- Case Else Disp_IPAddressData = Wry.Country
- End Select
- End Function
- ' ============================================
- ' 返回QQWry信息
- ' ============================================
- Function WryInfo()
- Dim Wry, IPType, QQWry_tem(0), QQWry_tem1(1)
- ' 设置类对象
- Set Wry = New TQQWry
- IPType = Wry.QQWry("255.255.255.254")
- ' 读取数据库版本信息
- QQWry_tem(0) = Wry.Country & " " & Wry.LocalStr
- ' 读取数据库IP地址数目
- QQWry_tem1(1) = Wry.RecordCount + 1
- WryInfo = QQWry_tem(0)& " " & QQWry_tem1(1)
- End Function
- 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("QQWry.Dat")
- End Sub
- ' ============================================
- ' IP地址转换成整数
- ' ============================================
- Function IPToInt(IP)
- 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地址
- ' ============================================
- Function IntToIP(IntValue)
- p4 = IntValue - Fix(IntValue/256)*256
- IntValue = (IntValue-p4)/256
- p3 = IntValue - Fix(IntValue/256)*256
- IntValue = (IntValue-p3)/256
- p2 = IntValue - Fix(IntValue/256)*256
- IntValue = (IntValue - p2)/256
- p1 = IntValue
- IntToIP = Cstr(p1) & "." & Cstr(p2) & "." & Cstr(p3) & "." & Cstr(p4)
- End Function
- ' ============================================
- ' 获取开始IP位置
- ' ============================================
- Private Function GetStartIP(RecNo)
- OffSet = FirstStartIP + RecNo * 7
- Stream.Position = OffSet
- Buf = Stream.Read(7)
- EndIPOff = AscB(MidB(Buf, 5, 1)) + (AscB(MidB(Buf, 6, 1))*256) + (AscB(MidB(Buf, 7, 1))*256*256)
- StartIP = AscB(MidB(Buf, 1, 1)) + (AscB(MidB(Buf, 2, 1))*256) + (AscB(MidB(Buf, 3, 1))*256*256) + (AscB(MidB(Buf, 4, 1))*256*256*256)
- GetStartIP = StartIP
- End Function
- ' ============================================
- ' 获取结束IP位置
- ' ============================================
- Private Function GetEndIP()
- Stream.Position = EndIPOff
- Buf = Stream.Read(5)
- EndIP = AscB(MidB(Buf, 1, 1)) + (AscB(MidB(Buf, 2, 1))*256) + (AscB(MidB(Buf, 3, 1))*256*256) + (AscB(MidB(Buf, 4, 1))*256*256*256)
- CountryFlag = AscB(MidB(Buf, 5, 1))
- GetEndIP = EndIP
- End Function
- ' ============================================
- ' 获取地域信息,包含国家和和省市
- ' ============================================
- Private Sub GetCountry(IP)
- If (CountryFlag = 1 Or CountryFlag = 2) Then
- Country = GetFlagStr(EndIPOff + 4)
- If CountryFlag = 1 Then
- LocalStr = GetFlagStr(Stream.Position)
- ' 以下用来获取数据库版本信息
- If IP >= IPToInt("255.255.255.0") And IP <= IPToInt("255.255.255.255") Then
- LocalStr = GetFlagStr(EndIPOff + 21)
- Country = GetFlagStr(EndIPOff + 12)
- End If
- Else
- LocalStr = GetFlagStr(EndIPOff + 8)
- End If
- Else
- Country = GetFlagStr(EndIPOff + 4)
- LocalStr = GetFlagStr(Stream.Position)
- End If
- ' 过滤数据库中的无用信息
- Country = Trim(Country)
- LocalStr = Trim(LocalStr)
- If InStr(Country, "CZ88.NET") Then Country = ""
- If InStr(LocalStr, "CZ88.NET") Then LocalStr = ""
- End Sub
- ' ============================================
- ' 获取IP地址标识符
- ' ============================================
- Private Function GetFlagStr(OffSet)
- Dim Flag
- Flag = 0
- Do While (True)
- Stream.Position = OffSet
- Flag = AscB(Stream.Read(1))
- If(Flag = 1 Or Flag = 2 ) Then
- Buf = Stream.Read(3)
- If (Flag = 2 ) Then
- CountryFlag = 2
- EndIPOff = OffSet - 4
- End If
- OffSet = AscB(MidB(Buf, 1, 1)) + (AscB(MidB(Buf, 2, 1))*256) + (AscB(MidB(Buf, 3, 1))*256*256)
- Else
- Exit Do
- End If
- Loop
- If (OffSet < 12 ) Then
- GetFlagStr = ""
- Else
- Stream.Position = OffSet
- GetFlagStr = GetStr()
- End If
- End Function
- ' ============================================
- ' 获取字串信息
- ' ============================================
- Private Function GetStr()
- Dim c
- GetStr = ""
- Do While (True)
- c = AscB(Stream.Read(1))
- If (c = 0) Then Exit Do
- '如果是双字节,就进行高字节在结合低字节合成一个字符
- If c > 127 Then
- If Stream.EOS Then Exit Do
- GetStr = GetStr & Chr(AscW(ChrB(AscB(Stream.Read(1))) & ChrB(C)))
- Else
- GetStr = GetStr & Chr(c)
- End If
- Loop
- End Function
- ' ============================================
- ' 核心函数,执行IP搜索
- ' ============================================
- Public Function QQWry(DotIP)
- Dim IP, nRet
- Dim RangB, RangE, RecNo
- IP = IPToInt (DotIP)
- Set Stream = CreateObject("ADodb.Stream")
- Stream.Mode = 3
- Stream.Type = 1
- Stream.Open
- Stream.LoadFromFile QQWryFile
- Stream.Position = 0
- Buf = Stream.Read(8)
- FirstStartIP = AscB(MidB(Buf, 1, 1)) + (AscB(MidB(Buf, 2, 1))*256) + (AscB(MidB(Buf, 3, 1))*256*256) + (AscB(MidB(Buf, 4, 1))*256*256*256)
- LastStartIP = AscB(MidB(Buf, 5, 1)) + (AscB(MidB(Buf, 6, 1))*256) + (AscB(MidB(Buf, 7, 1))*256*256) + (AscB(MidB(Buf, 8, 1))*256*256*256)
- RecordCount = Int((LastStartIP - FirstStartIP)/7)
- ' 在数据库中找不到任何IP地址
- If (RecordCount <= 1) Then
- Country = "未知"
- QQWry = 2
- Exit Function
- End If
- RangB = 0
- RangE = RecordCount
- Do While (RangB < (RangE - 1))
- RecNo = Int((RangB + RangE)/2)
- Call GetStartIP (RecNo)
- If (IP = StartIP) Then
- RangB = RecNo
- Exit Do
- End If
- If (IP > StartIP) Then
- RangB = RecNo
- Else
- RangE = RecNo
- End If
- Loop
- Call GetStartIP(RangB)
- Call GetEndIP()
- If (StartIP <= IP) And ( EndIP >= IP) Then
- ' 没有找到
- nRet = 0
- Else
- ' 正常
- nRet = 3
- End If
- Call GetCountry(IP)
- QQWry = nRet
- End Function
- ' ============================================
- ' 类终结
- ' ============================================
- Private Sub Class_Terminate
- On ErrOr Resume Next
- Stream.Close
- If Err Then Err.Clear
- Set Stream = Nothing
- End Sub
- End Class
- %>
- ?>
加入网摘
订阅
上一篇
返回
下一篇
标签:
