独立主机防火墙端口自动设置脚本[网络技术]
本文“独立主机防火墙端口自动设置脚本[网络技术]”是由七道奇为您精心收集,来源于网络转载,文章版权归文章作者所有,本站不对其观点以及内容做任何评价,请读者自行判断,以下是其具体内容:
本脚本功效,自动开启网卡中 TCP/IP 挑选器功效,然后自动批量增添您定义的端口,非常便利,普通设置了IP过滤便可以不用Windows防火墙了,在win2003上测试通过,假如看不懂或远程端口不是3389的请不要直接运行,您自己要改正下,假如认为好别忘了注明出处.
利用办法:将以下代码存为1.vbs放在C:\然后运行cscript c:\1.vbs 或直接双击此vbs文件也可以.
On Error Resume Next
Const ALLOW_ALL = "0" '0表示全部答应,空表示全部回绝,自定义用逗号离隔
arrPermittedTCPPorts = Array(ALLOW_ALL) 'TCP端口
arrPermittedTCPPorts = Array("20", "21", "25", "80", "110", "1433", "3306", "33000", "33001", "33002", "33003", "3389")
arrPermittedUDPPorts = Array("") 'UDP端口
arrPermittedIPProtocols = Array(ALLOW_ALL) 'IP协议
strComputer = "." '计算机名
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
Set colNicConfig = objWMIService.ExecQuery _
("Select * From Win32_NetworkAdapterConfiguration Where IPEnabled = True")
For Each objNicConfig in colNicConfig
WScript.Echo VbCrLf & " Network Adapter " & objNicConfig.Index
If not objNicConfig.IPFilterSecurityEnabled Then
WScript.Echo "正在启动 TCP/IP 挑选功效..."
Call enableipfilter()
end if
WScript.Echo "正在设置 TCP/IP 挑选端口与协议..."
intIPSecReturn = objNicConfig.EnableIPSec(arrPermittedTCPPorts, _
arrPermittedUDPPorts, arrPermittedIPProtocols)
If intIPSecReturn = 0 Then
WScript.Echo "成功"
ElseIf intIPSecReturn = 1 Then
WScript.Echo "成功,重启后见效."
Else
WScript.Echo "失利"
End If
Next
sub enableipfilter()
dim objAllNicsConfig , intFilterReturn
Set objAllNicsConfig = objWMIService.Get("Win32_NetworkAdapterConfiguration")
intFilterReturn = objAllNicsConfig.EnableIPFilterSec(True)
If intFilterReturn = 0 Then
WScript.Echo "成功"
SpecifyFilters
ElseIf intFilterReturn = 1 Then
WScript.Echo "成功,重启后见效."
Else
WScript.Echo "失利"
End If
end sub
WScript.Echo vbcrlf & vbcrlf & "本程序运行完毕 by SUN"
以上是“独立主机防火墙端口自动设置脚本[网络技术]”的内容,如果你对以上该文章内容感兴趣,你可以看看七道奇为您推荐以下文章:
本文地址: | 与您的QQ/BBS好友分享! |