[新手上路]批处理新手入门导读[视频教程]批处理基础视频教程[视频教程]VBS基础视频教程[批处理精品]批处理版照片整理器
[批处理精品]纯批处理备份&还原驱动[批处理精品]CMD命令50条不能说的秘密[在线下载]第三方命令行工具[在线帮助]VBScript / JScript 在线参考
返回列表 发帖

[问题求助] [已解决]PowerShell怎么给指定的防火墙规则添加一个IP

本帖最后由 522235677 于 2022-5-30 14:28 编辑

继之前的帖子 http://www.bathome.net/thread-62803-1-1.html 感谢@flashercs大佬的帮助
现在想利用powershell给防火墙规则添加一个IP地址,之前也尝试过用bat netsh命令配置防火墙,但是不太方便,添加IP的必须要先获取之前配置的IP,然后在追加IP(如果直接添加一个新的IP地址,之前的IP就会被清空掉),有点麻烦。

现在想用ps来追加一个IP地址,不知道怎么操作,百度了一番没有成功,求大佬们指导

就是想在这个帖子中第一张截图的位置添加IP地址 https://blog.csdn.net/qishine/ar ... E-8DE1-C4201AE48CF0

  1. #requires -runasadministrator
  2. $firewallRuleDisplayName = "TestRule1"
  3. $newRemoteIP = '192.168.1.41-192.168.1.52', '192.168.2.0/255.255.255.0', '2002:93d8::/64', '10.10.2.79'
  4. Get-NetFirewallRule -DisplayName $firewallRuleDisplayName | ForEach-Object {
  5.   $addrfilter = $_ | Get-NetFirewallAddressFilter
  6.   $arrOldRemoteIP = $addrfilter.CimInstanceProperties['RemoteAddress'].Value
  7.   $arrNewRemoteIP = @(
  8.     if ($null -ne $arrOldRemoteIP) { $arrOldRemoteIP }
  9.     $newRemoteIP
  10.   ) | Sort-Object -Unique
  11.   $_ | Set-NetFirewallRule -RemoteAddress $arrNewRemoteIP
  12. }
复制代码
微信:flashercs
QQ:49908356

TOP

回复 2# flashercs


    感谢大佬帮助,测试成功。给大佬发个小红包

再请教一个问题,我用curl执行一个请求,url其实是返回了一个IP地址,怎么把返回的内容(ip)赋予一个变量
  1. StatusCode        : 200
  2. StatusDescription : OK
  3. Content           : 192.168.10.123
  4. RawContent        : HTTP/1.1 200 OK
  5.                     Upgrade: h2,h2c,http/2
  6.                     Connection: Upgrade, close
  7.                     Content-Length: 14
  8.                     Content-Type: text/html; charset=UTF-8
  9.                     Date: Mon, 30 May 2022 04:54:55 GMT
  10.                     Server: ...
  11. Forms             : {}
  12. Headers           : {[Upgrade, h2,h2c,http/2], [Connection, Upgrade, close], [Content-Length, 14
  13.                     ]...}
  14. Images            : {}
  15. InputFields       : {}
  16. Links             : {}
  17. ParsedHtml        : mshtml.HTMLDocumentClass
  18. RawContentLength  : 14
复制代码

TOP

回复 3# 522235677
  1. $ip=(curl "http://test.com").Content
复制代码
微信:flashercs
QQ:49908356

TOP

回复 4# flashercs


    感谢大佬,成功了

TOP

返回列表