Windows大量新增防火牆例外連接埠的批處理代碼_DOS/BAT

來源:互聯網
上載者:User
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.
然後修改內容,把裡面的set用delete代替(別告訴我誰不會用替換).然後把後面的名字和enable用空格代替.內容如下:
netsh firewall delete portopening all 3230
........
以下如果要刪除那些連接埠,就可以直接這麼用它了.

其實方法真是太簡單,只是耗體力,所以決定用excel,而且可以搭配使用word(word可以方便替換特殊符號比如說定位字元).這樣就容易多了.
見笑了.
相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.