返回列表 发帖

[问题求助] [已解决]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

#requires -runasadministrator
$firewallRuleDisplayName = "TestRule1"
$newRemoteIP = '192.168.1.41-192.168.1.52', '192.168.2.0/255.255.255.0', '2002:93d8::/64', '10.10.2.79'
Get-NetFirewallRule -DisplayName $firewallRuleDisplayName | ForEach-Object {
  $addrfilter = $_ | Get-NetFirewallAddressFilter
  $arrOldRemoteIP = $addrfilter.CimInstanceProperties['RemoteAddress'].Value
  $arrNewRemoteIP = @(
    if ($null -ne $arrOldRemoteIP) { $arrOldRemoteIP }
    $newRemoteIP
  ) | Sort-Object -Unique
  $_ | Set-NetFirewallRule -RemoteAddress $arrNewRemoteIP
}COPY
微信:flashercs
QQ:49908356

TOP

回复 2# flashercs


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

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

TOP

回复 3# 522235677
$ip=(curl "http://test.com").ContentCOPY
微信:flashercs
QQ:49908356

TOP

回复 4# flashercs


    感谢大佬,成功了

TOP

返回列表