To empty the IIS log's self-logged in IP vbs (for research only)

Source: Internet
Author: User
Tags iis log
IIS Option Explicit

Dim Sourcefile,ipaddress,objargs

Const destfile= "Tempfile"
Const ForWriting = 2

Dim Text
Dim Fso,objnet,serviceobj
Dim Txtstream, Txtstreamout

Set Objargs = wscript.arguments
If Objargs.count = 2 Then
Sourcefile=objargs (0)
Ipaddress=objargs (1)
Else
WScript.Echo "Parameter Error" + vbCrLf
WScript. Echo "USAGE:KillLog.vbs logfilename yourip."
WScript. Quit 1
End If


Set fso = CreateObject ("Scripting.FileSystemObject")
If FSO. FileExists (sourcefile) Then
Set objnet = WScript.CreateObject ("Wscript.Network")
Set serviceobj = GetObject ("winnt://" & Objnet.computername & "/w3svc")
Set objnet=nothing
Serviceobj.stop
Wscript.Sleep 6000
Set Txtstream = fso. OpenTextFile (sourcefile)
Set txtstreamout = fso. OpenTextFile (DestFile, ForWriting, True)
Do as not (Txtstream.atendofstream)
Text = Txtstream.readline
If InStr (text,ipaddress) =0 Then
Txtstreamout.writeline Text
End If
Loop

Set Txtstream = Nothing
Set txtstreamout = Nothing

WScript.Echo "The Log file--" & sourcefile & "has cleaned your ip!"
Else
WScript.Echo "The Log file--" & SourceFile & "has not found!"
Wscript.Quit
End If
Fso. CopyFile DestFile, SourceFile
Fso.deletefile DestFile
Set fso=nothing
Serviceobj.start
Set serviceobj = Nothing



Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.