Configure TCP filtering (VBScript)
This code can be found in
Chapter 3 of Windows Server 2003 Security Cookbook
Purchase XP Cookbook or Networking Recipes for only $25 plus shipping! While supplies last.
Find out how to download all of the VBScript code from this site.
' This code enables IP Filtering for all adapters and configures
' filtering for all IP-enabled adapters.
' ------ SCRIPT CONFIGURATION ------
strComputer = "."
arrTCPPorts = Array ( 0 ) ' Allow all TCP ports
arrUDPPorts = Array ( 0 ) ' Allow all UDP ports
arrProtos = Array ( 80, 25 ) ' Allow only HTTP and SMTP
' ------ END CONFIGURATION ---------
set objWMI = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
set objAdapterConfig = objWMI.Get("Win32_NetworkAdapterConfiguration")
intRC = objAdapterConfig.EnableIPFilterSec( True )
if intRC = 0 then
WScript.Echo "IP Filtering for all adapters enabled"
elseif intRC = 1 then
WScript.Echo "IP Filtering enabled for all adapters, " & _
"but you must reboot for the changes to take effect"
else
WScript.Echo "There was an error enabling IP Filtering for all " & _
"adapters: " & intRC
end if
set colNAConfigs = objWMI.ExecQuery( _
"select * " & _
" from Win32_NetworkAdapterConfiguration " & _
" where IPEnabled = True" )
for each objNAConfig in colNAConfigs
intRC = objNAConfig.EnableIPSec( arrTCPPorts, arrUDPPorts, arrProtos )
if intRC = 0 then
WScript.Echo "IP Filtering configured for '" & _
objNAConfig.Description & "'"
elseif intRC = 1 then
WScript.Echo "IP Filtering configured for '" & objNAConfig.Description & _
"', but you must reboot for the changes to take effect"
else
WScript.Echo "There was an error configuring IP Filtering for '" & _
objNAConfig.Description & "': " & intRC
end if
next
|
This code has been viewed 1134 times.
|
New from the creators of TechTasks.com:
StatSheet.com
|