web发布IIS日志代码

1.数据库连接代码
下载: conn.asp
  1. <%
  2.  
  3.  dim startime
  4.  dim conn
  5.  dim connstr
  6.  dim db,pass_word,User_ID,Data_Source
  7.  startime=timer()
  8.  db="" '数据库名称
  9. Pass_word="" 'Password=帐号密码
  10.  User_ID="sa" 'User ID=登陆帐号
  11. Data_Source="localhost" 'Data Source=服务名称或者ip
  12.  
  13.  Set conn = Server.CreateObject("ADODB.Connection")
  14.  connStr="Provider=SQLOLEDB.1;Password='"&pass_word&"';Persist Security Info=True;User ID='"&User_ID&"';Initial Catalog='"&db&"';Data Source='"&Data_Source&"'"
  15.  conn.Open connstr
  16.  function CloseDb
  17.  Conn.close
  18.  Set conn = Nothing
  19.  End Function
  20. %>

2.主页代码
下载: index.asp
  1. <!--#include file=conn.asp-->
  2. <!--#include file=ip.asp-->
  3. <!--#include file=Neeao_SqlIn.Asp-->
  4. <%
  5.  Dim rs,sql
  6.  set rs=Server.CreateObject("ADODB.RecordSet")
  7.  sql = "select top 2000 * from inetlog ORDER BY logtime DESC"
  8.  rs.open sql,conn,3
  9.  rs.pagesize=50
  10.  if request("page")<>"" then
  11.  epage=cint(request("page"))
  12.  if epage<1 then epage=1
  13.  if epage>rs.pagecount then epage=rs.pagecount
  14.  else
  15.  epage=1
  16.  end if
  17.  rs.absolutepage=epage
  18.  'response.write "("&rs("ClientHost")&")"
  19.  'response.write "("&rs("LogTime")&")"
  20.  'response.write "("&rs("service")&")"
  21.  'response.write "("&rs("serverip")&")"
  22.  'response.write "("&rs("processingtime")&")"
  23.  'response.write "("&rs("bytesrecvd")&")"
  24.  'response.write "("&rs("servicestatus")&")"
  25.  'response.write "("&rs("win32status")&")"
  26.  'response.write "("&rs("operation")&")"
  27.  'response.write "("&rs("target")&")"
  28.  'response.write "("&rs("parameters")&")"
  29.  'ip=rs("ClientHost")
  30. %>
  31. <style type="text/css">
  32. <!--
  33. .STYLE2 {color: #FF0000}
  34. .STYLE3 {color: #003399}
  35. .STYLE4 {
  36.  color: #FF0000;
  37.  font-family: "宋体";
  38.  font-size: 24px;
  39.  }
  40. .STYLE5 {color: #FF0000; font-family: "宋体"; font-size: 14px; }
  41. .STYLE6 {color: #009933}
  42. -->
  43. </style>
  44. <title>Nod32升级服务器信息</title>
  45. <p> </p>
  46. <p align="center" class="STYLE6"> </p>
  47. <table width="362" border="0" align="center">
  48. <tr>
  49. <td width="356"><div align="center"><span class="STYLE4">Nod32升级服务器即时信息统计表</span></div></td>
  50. </tr>
  51. </table>
  52. <table width="300" border="0" align="center">
  53. <tr>
  54. <td width="294"><div align="center" class="STYLE5">由于数据比较庞大,本站只提供部分升级信息</div></td>
  55. </tr>
  56. </table>
  57. <p align="center"><span class="STYLE6">
  58. <%
  59.  IP = request("IP")
  60.  If IP = "" then
  61.  IP = Request.ServerVariables("REMOTE_ADDR")
  62. %>
  63. 嗨!你的IP是:<%=IP%>,来自<%=Disp_IPAddressData(IP,2)%><%=Disp_IPAddressData(IP,3)%>的朋友,i will intoyourbody now!
  64. <%else%>
  65. <%End if%>
  66. </span></p>
  67. <p align="center">服务器线路:安徽电信</p>
  68. <p align="center"> 升级服务器信息I: <a href="http://corbie.2288.org">http://corbie.2288.org</a> 服务器状态:<span class="STYLE2">在线</span></p>
  69. <p align="center"> 升级服务器信息II:<a href="http://eset.sifish.com.cn">http://eset.sifish.com.cn</a> 服务器状态:<span class="STYLE2">在线</span></p>
  70. <table width="87%" border="0" align="center" cellpadding="0" cellspacing="1" bgcolor="#0000FF">
  71. <tr bgcolor="#FFFFFF" align="center">
  72. <th width="15%"><span class="STYLE2">客户端ip</span></th>
  73. <th width="14%"><span class="STYLE2">客户端详细地址</span></th>
  74. <th width="23%"><span class="STYLE2">访问时间</span></th>
  75. <th width="17%"><span class="STYLE2">请求方式</span></th>
  76. <th width="15%"><span class="STYLE2">请求文件</span></th>
  77. <th width="16%"><span class="STYLE2">已读取字节</span></th>
  78. <th width="16%"><span class="STYLE2">状态</span></th>
  79. </tr>
  80. <%
  81.  for i=0 to rs.pagesize-1
  82.  if rs.bof or rs.eof then exit For
  83.  ip=rs("ClientHost")
  84. %>
  85.  
  86. <tr bgcolor="#FFFFFF" align="center">
  87. <th width="15%"><span class="STYLE3"><%=rs("ClientHost")%></span></th>
  88. <th width="14%"><span class="STYLE3"><%=Disp_IPAddressData(IP,2)%><%=Disp_IPAddressData(IP,3)%></th>
  89. <th width="23%"><span class="STYLE3"><%=rs("LogTime")%></span></th>
  90. <th width="17%"><span class="STYLE3"><%=rs("operation")%></span></th>
  91. <th width="15%"><span class="STYLE3"><%=rs("target")%></span></th>
  92. <th width="16%"><span class="STYLE3"><%=rs("bytessent")%></span></th>
  93. <th width="16%"><span class="STYLE3"><%=rs("servicestatus")%></span></th>
  94. </tr>
  95. <%
  96.  rs.movenext()
  97.  next
  98. %>
  99.  
  100.  
  101.  
  102. <%
  103.  for i=0 to rs.pagesize-1
  104.  if rs.bof or rs.eof then exit For
  105.  ip=rs("ClientHost")
  106.  
  107. %>
  108. <%
  109.  rs.movenext()
  110.  next
  111. %>
  112. </table>
  113. <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>
  114. <p align="center">现在是第<%=epage%>页一共有<%=rs.pagecount%>页</p>
  115. <%
  116.  conn.close()
  117. %>
  118. <p> </p>


3.读取纯真IP数据库代码
下载: ip.asp
  1. <%
  2.  ' ============================================
  3.  ' 返回IP信息 Disp_IPAddressData(IP,0)
  4.  ' ============================================
  5. Function Look_Ip(IP)
  6. Dim Wry, IPType, QQWryVersion, IpCounter
  7.  ' 设置类对象
  8.  Set Wry = New TQQWry
  9.  ' 开始搜索,并返回搜索结果
  10.  ' 您可以根据 QQWry(IP) 返回值来判断该IP地址在数据库中是否存在,如果不存在可以执行其他的一些操作
  11.  ' 比如您自建一个数据库作为追捕等,这里我就不详细说明了
  12. IPType = Wry.QQWry(IP)
  13.  ' Country:国家地区字段
  14.  ' LocalStr:省市及其他信息字段
  15. Look_Ip =Wry.Country & "" & Wry.LocalStr
  16.  '''''Look_Ip = Wry.Country & ""
  17.  End Function
  18.  ' ============================================
  19.  ' 返回IP信息 JS调用
  20.  ' ============================================
  21. Function Disp_IPAddressData(IP, sType)
  22. Dim Wry, IPType
  23. Set Wry = New TQQWry
  24. IPType = Wry.QQWry(IP)
  25.  
  26. Select Case sType
  27. Case 1 Disp_IPAddressData = IP
  28. Case 2 Disp_IPAddressData = Wry.Country
  29. Case 3 Disp_IPAddressData = Wry.LocalStr
  30.  'Case Else Disp_IPAddressData = Wry.Country & "" & Wry.LocalStr
  31.  Case Else Disp_IPAddressData = Wry.Country
  32.  End Select
  33.  End Function
  34.  ' ============================================
  35.  ' 返回QQWry信息
  36.  ' ============================================
  37. Function WryInfo()
  38. Dim Wry, IPType, QQWry_tem(0), QQWry_tem1(1)
  39.  ' 设置类对象
  40.  Set Wry = New TQQWry
  41.  IPType = Wry.QQWry("255.255.255.254")
  42.  ' 读取数据库版本信息
  43. QQWry_tem(0) = Wry.Country & " " & Wry.LocalStr
  44.  ' 读取数据库IP地址数目
  45.  QQWry_tem1(1) = Wry.RecordCount + 1
  46.  WryInfo = QQWry_tem(0)& " " & QQWry_tem1(1)
  47.  End Function
  48.  
  49.  Class TQQWry
  50.  ' ============================================
  51.  ' 变量声名
  52.  ' ============================================
  53. Dim Country, LocalStr, Buf, OffSet
  54. Private StartIP, EndIP, CountryFlag
  55. Public QQWryFile
  56. Public FirstStartIP, LastStartIP, RecordCount
  57. Private Stream, EndIPOff
  58.  ' ============================================
  59.  ' 类模块初始化
  60.  ' ============================================
  61.  Private Sub Class_Initialize
  62.  Country = ""
  63.  LocalStr = ""
  64.  StartIP = 0
  65.  EndIP = 0
  66.  CountryFlag = 0
  67.  FirstStartIP = 0
  68.  LastStartIP = 0
  69.  EndIPOff = 0
  70.  QQWryFile = Server.MapPath("QQWry.Dat")
  71.  End Sub
  72.  ' ============================================
  73.  ' IP地址转换成整数
  74.  ' ============================================
  75. Function IPToInt(IP)
  76. Dim IPArray, i
  77. IPArray = Split(IP, ".", -1)
  78. FOr i = 0 to 3
  79. If Not IsNumeric(IPArray(i)) Then IPArray(i) = 0
  80. If CInt(IPArray(i)) < 0 Then IPArray(i) = Abs(CInt(IPArray(i)))
  81. If CInt(IPArray(i)) > 255 Then IPArray(i) = 255
  82. Next
  83. IPToInt = (CInt(IPArray(0))*256*256*256) + (CInt(IPArray(1))*256*256) + (CInt(IPArray(2))*256) + CInt(IPArray(3))
  84. End Function
  85.  ' ============================================
  86.  ' 整数逆转IP地址
  87.  ' ============================================
  88.  Function IntToIP(IntValue)
  89.  p4 = IntValue - Fix(IntValue/256)*256
  90.  IntValue = (IntValue-p4)/256
  91.  p3 = IntValue - Fix(IntValue/256)*256
  92.  IntValue = (IntValue-p3)/256
  93.  
  94.  p2 = IntValue - Fix(IntValue/256)*256
  95.  IntValue = (IntValue - p2)/256
  96.  p1 = IntValue
  97.  IntToIP = Cstr(p1) & "." & Cstr(p2) & "." & Cstr(p3) & "." & Cstr(p4)
  98.  End Function
  99.  ' ============================================
  100.  ' 获取开始IP位置
  101.  ' ============================================
  102. Private Function GetStartIP(RecNo)
  103. OffSet = FirstStartIP + RecNo * 7
  104. Stream.Position = OffSet
  105. Buf = Stream.Read(7)
  106.  
  107. EndIPOff = AscB(MidB(Buf, 5, 1)) + (AscB(MidB(Buf, 6, 1))*256) + (AscB(MidB(Buf, 7, 1))*256*256)
  108. 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)
  109. GetStartIP = StartIP
  110. End Function
  111.  ' ============================================
  112.  ' 获取结束IP位置
  113.  ' ============================================
  114.  Private Function GetEndIP()
  115.  Stream.Position = EndIPOff
  116.  Buf = Stream.Read(5)
  117.  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)
  118.  CountryFlag = AscB(MidB(Buf, 5, 1))
  119.  GetEndIP = EndIP
  120.  End Function
  121.  ' ============================================
  122.  ' 获取地域信息,包含国家和和省市
  123.  ' ============================================
  124. Private Sub GetCountry(IP)
  125. If (CountryFlag = 1 Or CountryFlag = 2) Then
  126. Country = GetFlagStr(EndIPOff + 4)
  127. If CountryFlag = 1 Then
  128. LocalStr = GetFlagStr(Stream.Position)
  129.  ' 以下用来获取数据库版本信息
  130.  If IP >= IPToInt("255.255.255.0") And IP <= IPToInt("255.255.255.255") Then
  131.  LocalStr = GetFlagStr(EndIPOff + 21)
  132.  Country = GetFlagStr(EndIPOff + 12)
  133.  End If
  134.  Else
  135.  LocalStr = GetFlagStr(EndIPOff + 8)
  136.  End If
  137.  Else
  138.  Country = GetFlagStr(EndIPOff + 4)
  139.  LocalStr = GetFlagStr(Stream.Position)
  140.  End If
  141.  ' 过滤数据库中的无用信息
  142. Country = Trim(Country)
  143. LocalStr = Trim(LocalStr)
  144. If InStr(Country, "CZ88.NET") Then Country = ""
  145. If InStr(LocalStr, "CZ88.NET") Then LocalStr = ""
  146. End Sub
  147.  ' ============================================
  148.  ' 获取IP地址标识符
  149.  ' ============================================
  150.  Private Function GetFlagStr(OffSet)
  151.  Dim Flag
  152.  Flag = 0
  153.  Do While (True)
  154.  Stream.Position = OffSet
  155.  Flag = AscB(Stream.Read(1))
  156.  If(Flag = 1 Or Flag = 2 ) Then
  157.  Buf = Stream.Read(3)
  158.  If (Flag = 2 ) Then
  159.  CountryFlag = 2
  160.  EndIPOff = OffSet - 4
  161.  End If
  162.  OffSet = AscB(MidB(Buf, 1, 1)) + (AscB(MidB(Buf, 2, 1))*256) + (AscB(MidB(Buf, 3, 1))*256*256)
  163.  Else
  164.  Exit Do
  165.  End If
  166.  Loop
  167.  
  168.  If (OffSet < 12 ) Then
  169.  GetFlagStr = ""
  170.  Else
  171.  Stream.Position = OffSet
  172.  GetFlagStr = GetStr()
  173.  End If
  174.  End Function
  175.  ' ============================================
  176.  ' 获取字串信息
  177.  ' ============================================
  178. Private Function GetStr()
  179. Dim c
  180. GetStr = ""
  181. Do While (True)
  182. c = AscB(Stream.Read(1))
  183. If (c = 0) Then Exit Do
  184.  
  185.  '如果是双字节,就进行高字节在结合低字节合成一个字符
  186.  If c > 127 Then
  187.  If Stream.EOS Then Exit Do
  188.  GetStr = GetStr & Chr(AscW(ChrB(AscB(Stream.Read(1))) & ChrB(C)))
  189.  Else
  190.  GetStr = GetStr & Chr(c)
  191.  End If
  192.  Loop
  193.  End Function
  194.  ' ============================================
  195.  ' 核心函数,执行IP搜索
  196.  ' ============================================
  197. Public Function QQWry(DotIP)
  198. Dim IP, nRet
  199. Dim RangB, RangE, RecNo
  200.  
  201. IP = IPToInt (DotIP)
  202.  
  203. Set Stream = CreateObject("ADodb.Stream")
  204. Stream.Mode = 3
  205. Stream.Type = 1
  206. Stream.Open
  207. Stream.LoadFromFile QQWryFile
  208. Stream.Position = 0
  209. Buf = Stream.Read(8)
  210.  
  211. 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)
  212. 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)
  213. RecordCount = Int((LastStartIP - FirstStartIP)/7)
  214.  ' 在数据库中找不到任何IP地址
  215.  If (RecordCount <= 1) Then
  216.  Country = "未知"
  217.  QQWry = 2
  218.  Exit Function
  219.  End If
  220.  
  221.  RangB = 0
  222.  RangE = RecordCount
  223.  
  224.  Do While (RangB < (RangE - 1))
  225.  RecNo = Int((RangB + RangE)/2)
  226.  Call GetStartIP (RecNo)
  227.  If (IP = StartIP) Then
  228.  RangB = RecNo
  229.  Exit Do
  230.  End If
  231.  If (IP > StartIP) Then
  232.  RangB = RecNo
  233.  Else
  234.  RangE = RecNo
  235.  End If
  236.  Loop
  237.  
  238.  Call GetStartIP(RangB)
  239.  Call GetEndIP()
  240.  
  241.  If (StartIP <= IP) And ( EndIP >= IP) Then
  242.  ' 没有找到
  243. nRet = 0
  244. Else
  245.  ' 正常
  246.  nRet = 3
  247.  End If
  248.  Call GetCountry(IP)
  249.  
  250.  QQWry = nRet
  251.  End Function
  252.  ' ============================================
  253.  ' 类终结
  254.  ' ============================================
  255. Private Sub Class_Terminate
  256. On ErrOr Resume Next
  257. Stream.Close
  258. If Err Then Err.Clear
  259. Set Stream = Nothing
  260. End Sub
  261. End Class
  262. %>
  263. ?>
引用通告地址: 点击获取引用地址
标签: corbie,web,iis,iis日志
评论: 0 | 引用: 0 | 阅读: 241 | 打印 | 打包 | 转发
 加入网摘