Use VBScript to add IP policy automatic seal ip_vbs

Source: Internet
Author: User
The program mainly reads the IIS log of this website, analyzes the IP address, and automatically closes with security policy. The VBS code is as follows:
Copy Code code as follows:

' Code starts

Set fileobj=createobject ("Scripting.FileSystemObject")
Logfilepath= "E:w3logw3svc237ex070512old.log" note specifies the log path for the attacked Web site.
' If it is a virtual host, to find out which site is under attack, you can view: C:windowssystem32logfileshttperr,

It is easy to analyze from the error log.
Writelog "netsh ipsec static add policy Name=xblue"
Writelog "netsh ipsec static add filterlist Name=denyip"

Overip= ""
F_name=logfilepath
' Specify log file

' Program function: Extract IP from logfiles into the filtering format required by IPSec, and import filtering into IPSec. Suitable for a site subject to a large number of CC attacks.

Set Fileobj88=createobject ("Scripting.FileSystemObject")
Set myfile=fileobj88. OpenTextFile (F_name,1,false)
Contentover=myfile. ReadAll ()
Contentip=lcase (Contentover)
Myfile.close
Set fileobj88=nothing
On Error Resume Next
Myline=split (CONTENTIP,CHR (13))
For i=0 to UBound (myline)-1

Myline2=split (Myline (i), "")
Newip=myline2 (6)
' Specifies the detached identity string!
If InStr (OVERIP,NEWIP) =0 Then ' removes duplicate IP.
Overip=overip&newip
Dsafasf=split (Newip, ".")
If UBound (dsafasf) =3 Then
Writelog "netsh ipsec static add filter Filterlist=denyip srcaddr=" &newip& "Dstaddr=me

Dstport=80 protocol=tcp "
End If
Else
WScript.Echo Newip & "is exits!"
End If
Next
Writelog "netsh ipsec static add filteraction name=denyact Action=block"
Writelog "netsh ipsec static add rule name=kill3389 Policy=xblue Filterlist=denyip

Filteraction=denyact "
Writelog "netsh ipsec static set policy Name=xblue assign=y"


Sub writelog (errmes) ' Export IPSec policy file is a bat file.
Ipfilename= "Denyerrorip.bat"
Set Logfile=fileobj.opentextfile (ipfilename,8,true)
Logfile.writeline Errmes
Logfile.close
Set logfile=nothing
End Sub

' End of code

Save the above code as a. vbs file and set the path of the log. Double-click to run, and then generate a Denyerrorip.bat file after running, this is the policy file that IPSec needs, directly double-click to run.

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.