首页 > 系统相关 >windows添加防火墙规则

windows添加防火墙规则

时间:2024-03-06 14:36:35浏览次数:27  
标签:name windows 防火墙 rule firewall program advfirewall 添加 netsh

bat脚本如下,涉及到的函数主要是 netsh advfirewall firewall add rule 和 netsh advfirewall firewall delete rule

需要注意的一个坑是program的路径不能存在斜杠/,需要使用\,然而很多软件都会自动把路径生成为类似于C:/User/...这种形式,需要在脚本里转换一下

rem Check if both program path and program name are provided as arguments
if "%~1"=="" (
    echo Usage: %0 program_path program_name
    echo Example: %0 "C:\Path\to\your\program.exe" YourProgramName
    exit /b 1
)
if "%~2"=="" (
    echo Usage: %0 program_path program_name
    echo Example: %0 "C:\Path\to\your\program.exe" YourProgramName
    exit /b 1
)

set "programPath=%~1"
set "programName=%~2"

rem 替换斜杠为反斜杠
set "programPath=%programPath:/=\%"

rem Delete firewall rule
netsh advfirewall firewall delete rule name="%programName%(TCP)"
netsh advfirewall firewall delete rule name="%programName%(UDP)"

rem Add firewall rule for TCP
netsh advfirewall firewall add rule name="%programName%(TCP)" dir=in program="%programPath%" action=allow protocol=TCP

rem Add firewall rule for UDP
netsh advfirewall firewall add rule name="%programName%(UDP)" dir=in program="%programPath%" action=allow protocol=UDP

echo Firewall rules for %programName% added successfully.

标签:name,windows,防火墙,rule,firewall,program,advfirewall,添加,netsh
From: https://www.cnblogs.com/miyanyan/p/18056479

相关文章

  • [转帖]linux-windows文件实时同步:Rsync使用教程
    http://luomuren.top/articles/2021/04/06/1617641017252.html#:~:text=linux-windows%E6%96%87%E4%BB%B6%E5%AE%9E%E6%97%B6%E5%90%8C%E6%AD%A5%EF%BC%9ARsync%E4%BD%BF%E7%94%A8%E6%95%99%E7%A8%8B%201%20%E4%B8%80%20%E3%80%81%E4%BB%80%E4%B9%88%E6%98%AFrync%20%EF%BC%9F......
  • Windows使用SIDCHG64 修改SID
    1、网站下载工具:https://www.stratesave.com/html/sidchg.html2、执行命令:sidchg64-3.0j.exe/KEY="************"/F/R注意:(1)sidchg有2个版本,标准版sidchg64和轻量版sidchgl64轻量版无需关闭defender实时防护,但是sid改得不彻底标准版执行之前需要关闭defender实时......
  • windows 查询占用端口进程并清理
    查找占用端口的进程号:netstat-ano|findstr9000根据进程号查找占用端口的进程信息(16240为进程号):tasklist|findstr16240关闭占用端口的进程:使用进程号(16240为进程号):taskkill/f/pid16240 2.使用进程名:taskkill /f ......
  • windows编译ZLMediaKit流媒体服务webrtc
    环境说明ZLMediaKit编译需要的软件visualstudio2022cmake3.29.0-rc2OpenSSL1.1.1w(不想踩坑的话安装这个版本)libsrtp2.6.0ZLMediaKit编译后运行需要libsrtp编译后且配置环境变量ZLMediaKit编译后文件visualstudiocmakevisualstuid......
  • Windows 下 强制修改 MySQL的 root 账号密码
    更新记录点击查看2024年3月6日发布。2024年2月6日初始化。关闭MySQL服务netstopMySQLnetstopMySQL57netstopMySQL80netstop自定义的服务名启动MySQL但不带权限转到mysql/bin目录然后执行mysqld–console–skip-grant-tables–shared-memory如果遇到......
  • div contenteditable="true" 添加placehoder效果
    <divclass="contain":style="{height:editableHeight+'px'}" v-html="innerText" ref="editableDiv" contenteditable="true" :placeholder=placeholder @input="inputTe......
  • PlatformIO+esp32+添加自己的库(.c.h文件)
        什么都放main.c的话,很有可能堆积成屎山,所以我想给分开写,每个功能有自己的.c、.h文件。在lib下新建文件夹,例如led,再在里面分别建led.c、led.h;写好内容后再main.h引用头文件led.h即可。(以上步骤没问题哈)但是我这样子看着没问题,但是一BUILD就会报错:undefinedrefere......
  • ems-jsp 添加职工功能
    1.思路接受前端的表单,将数据存入数据库。2.代码:controller:/**添加员工信息**/@RequestMapping("add")publicStringaddEmployee(Employeeemployee){log.debug("员工名称:{}",employee.getName());log.debug("员工工资:{}",......
  • nginx在windows下的使用二
    一、反向代理,多台机器1.需求和目的:nginx代理两台服务器,这两台服务器使用tomcat模拟浏览器访问http://localhost:9001/beijing/index.html,通过nginx,跳转到一个tomcat上(端口8080),浏览器上显示beijing浏览器访问http://localhost:9001/shanghai/index.html,通过nginx,跳转到一个tom......
  • centos7 xfreerdp安装及远程执行Windows脚本
    1、yuminstallfreerdp2、centos7需要安装桌面环境,并设置从桌面启动3、xfreerdp使用  xfreerdp/u:Administrator/p:Password123/drive:data,/root/app:cmd.exe/app-cmd:"cmd.exe/knetuseX:\\tsclient\data&X:&mimi.bat"/v:192.168.0.100  /u:账号 ......