自动添加端口添加至Windows防火墙脚本

copy一下文件内容到文本文档里,然后修改后缀名为".vbs"

,双击该脚本就可以把该文档里自定义的端口都自动添加到防火墙里了。

call Addfirewall("端口",端口,1)

例:

copy star:

'#####################

'VBS修改端口,并添加至Windows防火墙

'作者aizzw

'#####################

Function Addfirewall(name,port,state)

Set objFirewall = CreateObject("HNetCfg.FwMgr")

Set objPolicy = objFirewall.LocalPolicy.CurrentProfile

Set objPort = CreateObject("HNetCfg.FwOpenPort")

objPort.Port = port

objPort.Name = name

objPort.Enabled = state

Set colPorts = objPolicy.GloballyOpenPorts

errReturn = colPorts.Add(objPort)

End Function

call Addfirewall("1433",1433,1)

call Addfirewall("5201314",5201314,1)

call Addfirewall("7758",7758,1)

call Addfirewall("40302",40302,1)

call Addfirewall("45002",45002,1)

call Addfirewall("40003",40003,1)

call Addfirewall("41001",41001,1)

set WshShell = nothing

msgbox "端口已添加到防火墙"

stop copy

本文转自 idyllic_cyty 51CTO博客,原文链接:http://blog.51cto.com/aizzw/313372

上一篇:iptables/netfilter网络防火墙实现及实战分析
下一篇:教你如何开启/关闭ubuntu防火墙