防火墙网络放行

通常做设置时需要对指定的程序或端口进行防火墙放行

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
@echo off
 
rem 设置需要启动的端口
set OTHERPORT=1433,3389
 
rem 启用防火墙常规端口  可以删除
netsh advfirewall firewall add rule name="_Ping" dir=in protocol=icmpv4 action=allow
netsh advfirewall firewall add rule name="_20 FTP" protocol=TCP dir=in localport=20 action=allow
 
rem 启用防火墙非常规端口
FOR %%c in (%OTHERPORT%) do (
    SET PORT=%%c
    call :input
    call :output       
    )
 
pause
 
rem 入栈规则
:input
set INPUTPORT=%PORT%
set INPUT_RULE_NAME="_%INPUTPORT% 入栈规则"
netsh advfirewall firewall show rule name=%INPUT_RULE_NAME% >nul
if not ERRORLEVEL 1 (
    echo 对不起,规则 %INPUT_RULE_NAME% 已经存在
) else (
    netsh advfirewall firewall add rule name=%INPUT_RULE_NAME% dir=in action=allow protocol=TCP localport=%INPUTPORT%
    echo 规则 %INPUT_RULE_NAME% 创建成功
)
 
rem 出栈规则
:output
set OUTPORT=%PORT%
set OUT_RULE_NAME="_%OUTPORT% 出栈规则"
netsh advfirewall firewall show rule name=%OUT_RULE_NAME% >nul
if not ERRORLEVEL 1 (
echo 对不起,规则 %OUT_RULE_NAME% 已经存在
) else (
    netsh advfirewall firewall add rule name=%OUT_RULE_NAME% dir=out action=allow protocol=TCP localport=%OUTPORT%
    echo 规则 %OUT_RULE_NAME% 创建成功
)

 当然还有简单两句

1
2
netsh advfirewall firewall add rule name="AI" dir=in action=allow program="C:\XXX\ai\main.exe" enable=yes
netsh advfirewall firewall add rule name="AI" dir=out action=allow program="C:\XXX\ai\main.exe" enable=yes

 因为比较常见使用,故记录一下,当然保存的BAT记得管理员运行

 

posted @   stweily  阅读(69)  评论(0编辑  收藏  举报
努力加载评论中...
点击右上角即可分享
微信分享提示