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 可以方便替换特殊符号比如说制表符 ). 这样就容易多了 .
见笑了 .
在 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 可以方便替换特殊符号比如说制表符 ). 这样就容易多了 .
见笑了 .
转载于:https://blog.51cto.com/1690116/508726