TTraffic.asp
上传用户:shbosideng
上传日期:2013-05-04
资源大小:1555k
文件大小:6k
源码类别:

SNMP编程

开发平台:

C/C++

  1. <%
  2. '*******************************************************************************
  3. '*                                                                             *
  4. '* TTraffic 1.0.0 (distributed under GNU GENERAL PUBLIC LICENSE)              *
  5. '* by kamborio                                                                 *
  6. '*                                                                             *
  7. '* ------------------------------------------------------                      *
  8. '*  _                       _                   _                              *
  9. '* | | __  __ _  _ __ ___  | |__    ___   _ __ (_)  ___                        *
  10. '* | |/ / / _` || '_ ` _  | '_   / _  | '__|| | / _                        *
  11. '* |   < | (_| || | | | | || |_) || (_) || |   | || (_) |                      *
  12. '* |_|_ __,_||_| |_| |_||_.__/  ___/ |_|   |_| ___/                       *
  13. '* ------------------------------------------------------                      *
  14. '*                               http://www.kamborio.com/                      *
  15. '*                                                                             *
  16. '* Copyright (C) 2001 David A. P閞ez (david@kamborio.com)                      *
  17. '*                                                                             *
  18. '* This program is free software; you can redistribute it and/or modify it     *
  19. '* under the terms of the GNU General Public License as published by the Free  *
  20. '* Software Foundation; either version 2 of the License, or (at your option)   *
  21. '* any later version.                                                          *
  22. '*                                                                             *
  23. '* This program is distributed in the hope that it will be useful, but WITHOUT *
  24. '* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or       *
  25. '* FITNESS FOR A  PARTICULAR PURPOSE. See the GNU General Public License for   *
  26. '* more details.                                                               *
  27. '*                                                                             *
  28. '* You should have received a copy of the GNU General Public License along     *
  29. '* with this program; if not, write to the:                                    *
  30. '*                                                                             *
  31. '* Free Software Foundation, Inc.                                              *
  32. '* 59 Temple Place - Suite 330                                                 *
  33. '* Boston, MA 02111-1307, USA                                                  *
  34. '*                                                                             *
  35. '*******************************************************************************
  36. Const ForReading = 1, ForWriting = 2
  37. Dim LogsMode
  38. LogsMode = 1
  39. Dim Order, Period
  40. Dim fso, f, p, n, TheFile, LineNumber, TheLine, TheValues
  41. Dim ReadAt, LastRan, TotalBytesIn, TotalBytesOut
  42. Dim PeriodIn, PeriodOut, MonthIn, MonthOut
  43. Period = Request("Period")
  44. Order = Trim(CStr(Request("Order")))
  45. If Not IsNumeric(Period) Then
  46. Period = 30
  47. Else
  48. If Period < 1 Then
  49. Period = 30
  50. End If
  51. End If
  52. If Order = "" Then
  53. Order = "G"
  54. End If
  55. Set fso = CreateObject("Scripting.FileSystemObject")
  56. Set f = fso.GetFile(Request.ServerVariables("PATH_TRANSLATED"))
  57. If LogsMode = 1 Then
  58. ReDim p(0)
  59. p(0) = Replace(f.Name, ".asp", "") & ".log"
  60. Else
  61. p = Split(f.Path, "")
  62. For n = 1 To (UBound(p) - 2)
  63. p(0) = p(0) & "" & p(n)
  64. Next
  65. p(0) = p(0) & "logs" & p(n) & "" & Replace(f.Name, ".asp", "") & ".log"
  66. End If
  67. Set TheFile = fso.OpenTextFile(p(0), ForReading)
  68. LineNumber = -1
  69. While Not TheFile.AtEndOfStream
  70. LineNumber = LineNumber + 1
  71. TheLine = TheFile.ReadLine
  72. TheValues = Split(TheLine)
  73. If LineNumber = 0 Then
  74. LastRan = UNIXToDay(TheValues(0))
  75. TotalBytesIn = CDbl(TheValues(1))
  76. TotalBytesOut = CDbl(TheValues(2))
  77. Else
  78. If DateDiff("d", UNIXToDay(TheValues(0)), Now) < CLng(Period) Then
  79. PeriodIn = PeriodIn + CDbl(TheValues(1) * (ReadAt - TheValues(0)))
  80. PeriodOut = PeriodOut + CDbl(TheValues(2) * (ReadAt - TheValues(0)))
  81. End If
  82. If Month(UNIXToDay(TheValues(0))) = Month(Now) And Year(UNIXToDay(TheValues(0))) = Year(Now) Then
  83. MonthIn = MonthIn + CDbl(TheValues(1) * (ReadAt - TheValues(0)))
  84. MonthOut = MonthOut + CDbl(TheValues(2) * (ReadAt - TheValues(0)))
  85. End If
  86. End If
  87. ReadAt = TheValues(0)
  88. Wend
  89. Set TheFile = Nothing
  90. set f = Nothing
  91. Set fso = Nothing
  92. Response.Write "<HR><BR>"
  93. Response.Write "<TABLE><TR><TD>Interface:</TD>"
  94. Response.Write "<TD>" & BytesTo(TotalBytesIn, Order) & " In and " & BytesTo(TotalBytesOut, Order) & " Out</B>, making a total of " & BytesTo((TotalBytesIn + TotalBytesOut), Order) & "</TD></TR>"
  95. Response.Write "<TR><TD>" & MonthName(Month(Now)) & ":</TD>"
  96. Response.Write "<TD>" & BytesTo(MonthIn, Order) & " In and " & BytesTo(MonthOut, Order) & " Out, making a total of " & BytesTo((MonthIn + MonthOut), Order) & "</TD></TR>"
  97. Response.Write "<TR><TD>Last " & Period & " days:</TD>"
  98. Response.Write "<TD>" & BytesTo(PeriodIn, Order) & " In and " & BytesTo(PeriodOut, Order) & " Out, making a total of " & BytesTo((PeriodIn + PeriodOut), Order) & "</TD></TR></TABLE>"
  99. Function UNIXToDay(Value)
  100. UNIXToDay = DateAdd("s", Value, "1/Jan/1970 0:00")
  101. End Function
  102. Function BytesTo(Value, Order)
  103. Dim NumericalOrder, OrderName
  104. Select Case UCase(Order)
  105. Case "K"
  106. NumericalOrder = "1"
  107. OrderName = "Kb"
  108. Case "M"
  109. NumericalOrder = "2"
  110. OrderName = "Mb"
  111. Case "G"
  112. NumericalOrder = "3"
  113. OrderName = "Gb"
  114. Case "T"
  115. NumericalOrder = "4"
  116. OrderName = "Tb"
  117. Case "P"
  118. NumericalOrder = "5"
  119. OrderName = "Pb"
  120. Case Else
  121. NumericalOrder = "0"
  122. OrderName = "Bytes"
  123. End Select
  124. BytesTo = Round((Value / 1024 ^ NumericalOrder), 2) & " " & OrderName
  125. End Function
  126. %>