標籤:bat
【阻塞Windows防火牆連接埠做測試】firewall.win7.port.cn.bat
@echo offrem v1.0.2color 2ftitle Windows防火牆連接埠阻塞set dport=8000set direction=outgoto menu:menuset rule_name=block_tcp_%direction%_%dport%echo.echo 菜單:echo 1. 增加這條規則: echo [規則名:%rule_name%]echo [操作: 阻塞]echo [連接埠: %dport%]echo [方向: %direction%]echo 2. 刪除這條規則: echo [規則名: %rule_name%]echo 3. 設定新的連接埠和方向: echo [預設值: 連接埠=8000, 方向=out]echo 4. 顯示這條規則: echo [規則名: %rule_name%]echo 5. 顯示所有名稱以block_tcp開頭的規則: echo [規則名: 以“block_tcp”開頭]echo 8. 協助echo 9. 菜單echo 0. 退出echo _____________________________________________________________echo 注1:選擇數字,然後按斷行符號;echo.goto start:menu_helpecho.echo 操作方法:echo.echo → 按3(斷行符號):設定參數,樣本如下,echo 連接埠[8000]=9001(斷行符號)echo 方向[out]=(斷行符號)(即預設的out);echo → 按1(斷行符號):增加新規則“block_tcp_out_9001”到防火牆;echo → 按4(斷行符號):顯示當前規則“block_tcp_out_9001”;echo → 按2(斷行符號):刪除當前規則“block_tcp_out_9001”;echo 重複上述步驟,操作新的規則;echo → 按5(斷行符號):顯示所有名稱以“block_tcp”開頭的規則;echo 刪除前,請先確認當前設定的連接埠和方向。echo.goto start:startecho.echo [1(新增),2(刪除),3(設定),4(顯示),5(顯示所有)]echo -------------------------------------------------------------set choice=set /p choice=請選擇:echo.if /i "%choice%"=="" goto warnif /i %choice%==1 goto rule_addif /i %choice%==2 goto rule_delif /i %choice%==3 goto settingif /i %choice%==4 goto rule_showif /i %choice%==5 goto rule_show_allif /i %choice%==8 goto menu_helpif /i %choice%==9 goto menuif /i %choice%==0 goto end:warnecho 警告!輸入無效,請重新選擇!& goto start:rule_addnetsh advfirewall firewall add rule name="%rule_name%" dir=%direction% protocol=tcp remoteport=%dport% action=blockgoto start:rule_delnetsh advfirewall firewall del rule dir=%direction% name="%rule_name%"goto start:rule_shownetsh advfirewall firewall show rule dir=%direction% name="%rule_name%"goto start:rule_show_allnetsh advfirewall firewall show rule dir=%direction% name=all|findstr block_tcpgoto start:settingset dport=8000set /p dport=連接埠[8000]:echo %dport%|findstr "[^0-9]"echo %dport%|findstr "[^0-9]" > nul && goto setting || goto setting_2:setting_2set direction=outset /p direction=方向[out]:echo %direction%|findstr "in out" > nul && goto menu || goto setting_2:endexit
【阻塞Windows防火牆連接埠做測試】firewall.win7.port.cn.bat