Windows批量添加防火墻例外端口
代碼如下:
echo off
cls
set var=30000
set end=30010
:continue
set /a var+=1
echo add port %var%
netsh firewall add portopening TCP %var% ftp_data_%var%
if %var% lss %end% goto continue
echo complete
pause
下面的文章特色就是,如果是按順序的可以手工添加,也可以通過批處理 vbs js等批量輸出
例如:如下端口80,3389,4399,3001-3020....
就可以數組批量輸出更方便,就是下面的代碼了,具體的大家自己發揮吧
XP系統自帶防火墻批量添加端口到例外的簡便方法
今天在一臺電腦上裝了一軟件,需要添加好幾十個端口到防火墻例外里.結果發現竟然只能一個一個添加.在網上找了些做法,都是用VBS來批量添加.兄弟我沒學過VBS,不會用,所以就只好想到用老朋友bat文件了.結果發現還真行,特把方法記下來,以備下次再用.
在bat里給防火墻添加端口的語句如下:
Netsh firewall set portopening udp/tcp/all port_number name enable
所以,為了節省時間和體力,先新建一個excel文檔,在里面寫好要添加的語句,如下圖:
在這里,我給端口起的名字叫做polycom-端口號,然后選定所有記錄,復制到文本文檔里.并刪除名字中間的TAB符.這一步很容易,只是為了省點體力而已.如果不嫌麻煩,可以全部寫入到文本文檔里去,不過如果端口太多,工作量也不小.
然后把文本文檔保存成bat文件.內容如下:
代碼如下:
@echo off
rem 下面添加要加入到例外的端口號.這里使用all,表示TCP與UDP.如果只是tcp或UDP,可以改成相應的.
netsh firewall set portopening all 3230 polycom-3230 enable
netsh firewall set portopening all 3231 polycom-3231 enable
netsh firewall set portopening all 3232 polycom-3232 enable
netsh firewall set portopening all 3233 polycom-3233 enable
netsh firewall set portopening all 3234 polycom-3234 enable
netsh firewall set portopening all 3235 polycom-3235 enable
netsh firewall set portopening all 3236 polycom-3236 enable
netsh firewall set portopening all 3237 polycom-3237 enable
netsh firewall set portopening all 3238 polycom-3238 enable
netsh firewall set portopening all 3239 polycom-3239 enable
netsh firewall set portopening all 3240 polycom-3240 enable
netsh firewall set portopening all 3241 polycom-3241 enable
netsh firewall set portopening all 3242 polycom-3242 enable
netsh firewall set portopening all 3243 polycom-3243 enable
netsh firewall set portopening all 3244 polycom-3244 enable
netsh firewall set portopening all 3245 polycom-3245 enable
netsh firewall set portopening all 3246 polycom-3246 enable
exit
做好后保存成bat文件就可以了,我這里保存成polycom_port_add.bat文件.
這樣,執行此文件就大功告成了.
刪除的方法也很簡單,把這個文件做一個備份,重命名,我這里改成polycom_port_del.bat.