Windows批量添加防火墻例外端口的批處理代碼
更新時(shí)間:2012年11月10日 23:22:20 作者:
有時(shí)候我們需要添加很多端口到防火墻例外,如果一個(gè)一個(gè)手工添加很累,那么就可以利用下面的方法
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....
就可以數(shù)組批量輸出更方便,就是下面的代碼了,具體的大家自己發(fā)揮吧
XP系統(tǒng)自帶防火墻批量添加端口到例外的簡(jiǎn)便方法
今天在一臺(tái)電腦上裝了一軟件,需要添加好幾十個(gè)端口到防火墻例外里.結(jié)果發(fā)現(xiàn)竟然只能一個(gè)一個(gè)添加.在網(wǎng)上找了些做法,都是用VBS來批量添加.兄弟我沒學(xué)過VBS,不會(huì)用,所以就只好想到用老朋友bat文件了.結(jié)果發(fā)現(xiàn)還真行,特把方法記下來,以備下次再用.
在bat里給防火墻添加端口的語句如下:
Netsh firewall set portopening udp/tcp/all port_number name enable
所以,為了節(jié)省時(shí)間和體力,先新建一個(gè)excel文檔,在里面寫好要添加的語句,如下圖:
在這里,我給端口起的名字叫做polycom-端口號(hào),然后選定所有記錄,復(fù)制到文本文檔里.并刪除名字中間的TAB符.這一步很容易,只是為了省點(diǎn)體力而已.如果不嫌麻煩,可以全部寫入到文本文檔里去,不過如果端口太多,工作量也不小.
然后把文本文檔保存成bat文件.內(nèi)容如下:
@echo off
rem 下面添加要加入到例外的端口號(hào).這里使用all,表示TCP與UDP.如果只是tcp或UDP,可以改成相應(yīng)的.
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文件.
這樣,執(zhí)行此文件就大功告成了.
刪除的方法也很簡(jiǎn)單,把這個(gè)文件做一個(gè)備份,重命名,我這里改成polycom_port_del.bat.
然后修改內(nèi)容,把里面的set用delete代替(別告訴我誰不會(huì)用替換).然后把后面的名字和enable用空格代替.內(nèi)容如下:
netsh firewall delete portopening all 3230
........
以下如果要?jiǎng)h除那些端口,就可以直接這么用它了.
其實(shí)方法真是太簡(jiǎn)單,只是耗體力,所以決定用excel,而且可以搭配使用word(word可以方便替換特殊符號(hào)比如說制表符).這樣就容易多了.
見笑了.
復(fù)制代碼 代碼如下:
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....
就可以數(shù)組批量輸出更方便,就是下面的代碼了,具體的大家自己發(fā)揮吧
XP系統(tǒng)自帶防火墻批量添加端口到例外的簡(jiǎn)便方法
今天在一臺(tái)電腦上裝了一軟件,需要添加好幾十個(gè)端口到防火墻例外里.結(jié)果發(fā)現(xiàn)竟然只能一個(gè)一個(gè)添加.在網(wǎng)上找了些做法,都是用VBS來批量添加.兄弟我沒學(xué)過VBS,不會(huì)用,所以就只好想到用老朋友bat文件了.結(jié)果發(fā)現(xiàn)還真行,特把方法記下來,以備下次再用.
在bat里給防火墻添加端口的語句如下:
Netsh firewall set portopening udp/tcp/all port_number name enable
所以,為了節(jié)省時(shí)間和體力,先新建一個(gè)excel文檔,在里面寫好要添加的語句,如下圖:
在這里,我給端口起的名字叫做polycom-端口號(hào),然后選定所有記錄,復(fù)制到文本文檔里.并刪除名字中間的TAB符.這一步很容易,只是為了省點(diǎn)體力而已.如果不嫌麻煩,可以全部寫入到文本文檔里去,不過如果端口太多,工作量也不小.
然后把文本文檔保存成bat文件.內(nèi)容如下:
復(fù)制代碼 代碼如下:
@echo off
rem 下面添加要加入到例外的端口號(hào).這里使用all,表示TCP與UDP.如果只是tcp或UDP,可以改成相應(yīng)的.
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文件.
這樣,執(zhí)行此文件就大功告成了.
刪除的方法也很簡(jiǎn)單,把這個(gè)文件做一個(gè)備份,重命名,我這里改成polycom_port_del.bat.
然后修改內(nèi)容,把里面的set用delete代替(別告訴我誰不會(huì)用替換).然后把后面的名字和enable用空格代替.內(nèi)容如下:
netsh firewall delete portopening all 3230
........
以下如果要?jiǎng)h除那些端口,就可以直接這么用它了.
其實(shí)方法真是太簡(jiǎn)單,只是耗體力,所以決定用excel,而且可以搭配使用word(word可以方便替換特殊符號(hào)比如說制表符).這樣就容易多了.
見笑了.
您可能感興趣的文章:
- Windows server 2008 R2遠(yuǎn)程桌面3389端口的修改方法
- Windows 2012/IIS8多網(wǎng)站用相同端口部署多張證書(SNI)
- windows下nginx的安裝使用及解決80端口被占用nginx不能啟動(dòng)的問題
- WINDOWS SERVER 2008遠(yuǎn)程桌面端口修改方法
- Windows下bat批處理腳本使用telnet批量檢測(cè)遠(yuǎn)程端口小記
- Windows 2008 r2 防火墻設(shè)置端口例外的方法
- Windows自帶的端口轉(zhuǎn)發(fā)工具netsh使用方法
- windows apache多端口虛擬主機(jī)配置方法
- 如何解決Windows的80端口被System進(jìn)程占用問題
相關(guān)文章
批處理統(tǒng)計(jì)文件夾內(nèi)的所有文件的數(shù)量和總大小的bat
這篇文章主要介紹了批處理統(tǒng)計(jì)文件夾內(nèi)的所有文件的數(shù)量和總大小的bat,需要的朋友可以參考下2016-12-12Country使 MS-DOS 子系統(tǒng)能使用國(guó)際時(shí)間、日期、貨幣、大小寫轉(zhuǎn)換和小數(shù)分隔符
Country使 MS-DOS 子系統(tǒng)能使用國(guó)際時(shí)間、日期、貨幣、大小寫轉(zhuǎn)換和小數(shù)分隔符...2007-09-09DOS命令初學(xué)者基礎(chǔ)知識(shí)學(xué)習(xí)
DOS命令初學(xué)者基礎(chǔ)知識(shí)學(xué)習(xí)...2006-09-09XCOPY的高級(jí)使用:指定日期并且用EXCLUDE排除指定文件
這篇文章主要介紹了通過dos下的XCOPY命令實(shí)現(xiàn)復(fù)制指定日期并且用EXCLUDE排除指定文件的代碼,需要的朋友可以參考下2014-04-04