Download IP to Country Free Database from Software77.net


' Parse IIS Logs

d=Now
limit=d-5

Dim fso
Set fso = CreateObject("Scripting.Filesystemobject")

Dim dic
Set dic = CreateObject("Scripting.Dictionary")

Set ip = CreateObject("Vbsedit.iptocountry")

IfNot(fso.FileExists("iptocountry.bin")) Then
  If fso.FileExists("iptocountry.csv") Then
    ip.CreateDatabaseFromCsv"iptocountry.csv","iptocountry.bin"
  Else
    WScript.Quit
  EndIf
Else
  If fso.FileExists("iptocountry.csv") Then
    If fso.GetFile("iptocountry.csv").DateLastModified > _
          fso.GetFile("iptocountry.bin").DateLastModifiedThen
      ip.CreateDatabaseFromCsv"iptocountry.csv","iptocountry.bin"
    EndIf
  EndIf
EndIf

'if you need to convert a lot of IP addresses
ip.LoadDatabaseIntoMemory"iptocountry.bin"

Dim theDate,theTime,serviceName,serverName,serverIP
Dim method,uriStem,uriQuery,serverPort,username,clientIp,protocolVersion
Dim userAgent,cookie,referrer,host,protocolStatus
Dim subStatus,win32Status,bytesSentByServer,bytesReceived,timeTaken
  
DoWhile d>limit

  file = "C:\LogFiles\W3SVC4\u_ex" & mydatepart("yyyy",d) & mydatepart("m",d) & myDatepart("d",d) & ".log"

  IfNot(fso.FileExists(file)) then
    ExitDo
  Endif

  Dim ff
  Set ff = fso.OpenTextFile(file,1)

  Dowhilenot(ff.AtEndofstream)
    Dim str
    str = ff.ReadLine
  
    filterok=False
  
    If left(str,9)="#Fields: "Then
      ParseFieldNames split(Mid(str,10)," ")
    ElseIf Left(str,1)<>"#"Then
      filterok=True
      ParseFields split(str," ")
    EndIf
  
    If filterokThen
      code = ip.IpToCountry(clientIp)
      country = ip.CountryCodeToCountryName(code)
      WScript.Echo country
      WScript.Echo theDate,theTime,serviceName,serverName,serverIP
      WScript.Echo method,uriStem,uriQuery,serverPort,username,clientIp,protocolVersion
      WScript.Echo userAgent,cookie,referrer,host,protocolStatus
      WScript.Echo subStatus,win32Status,bytesSentByServer,bytesReceived,timeTaken
    EndIf
  Loop

  d=d-1
Loop

Sub ParseFields(arr)
  theDate=""
  If dic.Exists("date") Then
    theDate= arr(dic.Item("date"))
  EndIf

  theTime=""
  If dic.Exists("time") Then
    theTime= arr(dic.Item("time"))
  EndIf
  
  serviceName=""
  If dic.Exists("s-sitename") Then
    serviceName= arr(dic.Item("s-sitename"))
  EndIf

  serverName=""
  If dic.Exists("s-computername") Then
    serverName= arr(dic.Item("s-computername"))
  EndIf

  serverIP=""
  If dic.Exists("s-ip") Then
    serverIP= arr(dic.Item("s-ip"))
  EndIf

  method=""
  If dic.Exists("cs-method") Then
    method= arr(dic.Item("cs-method"))
  EndIf

  uriStem=""
  If dic.Exists("cs-uri-stem") Then
    uriStem= arr(dic.Item("cs-uri-stem"))
  EndIf

  uriQuery=""
  If dic.Exists("cs-uri-query") Then
    uriQuery= arr(dic.Item("cs-uri-query"))
  EndIf

  serverPort=""
  If dic.Exists("s-port") Then
    serverPort= arr(dic.Item("s-port"))
  EndIf

  username=""
  If dic.Exists("cs-username") Then
    username= arr(dic.Item("cs-username"))
  EndIf

  clientIp=""
  If dic.Exists("c-ip") Then
    clientIp= arr(dic.Item("c-ip"))
  EndIf

  protocolVersion=""
  If dic.Exists("cs-version") Then
    protocolVersion= arr(dic.Item("cs-version"))
  EndIf

  userAgent=""
  If dic.Exists("cs(User-Agent)") Then
    userAgent= arr(dic.Item("cs(User-Agent)"))
  EndIf

  cookie=""
  If dic.Exists("cs(Cookie)") Then
    cookie= arr(dic.Item("cs(Cookie)"))
  EndIf

  referrer=""
  If dic.Exists("cs(Referrer)") Then
    referrer= arr(dic.Item("cs(Referrer)"))
  EndIf

  host=""
  If dic.Exists("cs-host") Then
    host= arr(dic.Item("cs-host"))
  EndIf

  protocolStatus=""
  If dic.Exists("sc-status") Then
    protocolStatus= arr(dic.Item("sc-status"))
  EndIf

  subStatus=""
  If dic.Exists("sc-substatus") Then
    subStatus= arr(dic.Item("sc-substatus"))
  EndIf

  win32Status=""
  If dic.Exists("sc-win32-status") Then
    win32Status= arr(dic.Item("sc-win32-status"))
  EndIf

  bytesSentByServer=0
  If dic.Exists("sc-bytes") Then
    bytesSentByServer= arr(dic.Item("sc-bytes"))
  EndIf

  bytesReceived=0
  If dic.Exists("cs-bytes") Then
    bytesReceived= arr(dic.Item("cs-bytes"))
  EndIf

  timeTaken=0
  If dic.Exists("time-taken") Then
    timeTaken= arr(dic.Item("time-taken"))
  EndIf

EndSub

Sub ParseFieldNames(arr)
  dic.RemoveAll
  For i=0 to UBound(arr)
    dic.Add arr(i),i
  Next
EndSub

Function Mydatepart(attr,d)
  Dim v
  v = CStr(DatePart(attr,d))
  if Len(v)=1then
    v = "0" & v
  elseif len(v)>2then
     v = Right(v,2)
  endif
  Mydatepart=v
EndFunction

search for scripts

VbsEdit contains all these sample scripts!


Download Now!



Download   Home   Scripts

Copyright © 2001-2024 adersοft