防火墙设置

netstat -ant | ?({$_ -like "*:80*"}) |%{$_.Trim() -replace "\s{2,}"," " }|%{$_.split(' ')[2]}|%{$_.split(':')[0]}|Group-Object $_ | sort Count -Descending | Where-Object({$_.Count -ge 50}) |Select-Object Count,Name >  C:\Users\Administrator\Desktop\cports\ip.txt

####以上内容另存为一个'自动发现.PS1'文件
####以下内容另存为一个'自动禁止.PS1'文件
$ip=(get-content C:\Users\Administrator\Desktop\cports\ip.txt -totalcount 4)[-1]|%{$_.trim()}|%{$_.split()[-1]}
if ("$?" -eq "False")
{
echo "数据错误"
exit
}
if ((get-content C:\Users\Administrator\Desktop\cports\ip.txt -totalcount 4)[-1]|%{$_.trim()}|%{$_.split()[-1]}|%{$_.startswith("192")})
{
echo "不能操作私网IP"
exit
}
#$ip=Read-Host "请输入要禁止的IP"
$RULE_NAME=$ip
netsh advfirewall firewall show rule name=$RULE_NAME
if ("$?" -eq "True")
{
echo "对不起,规则 $RULE_NAME 已经存在"
}
else 
{
echo "规则 $RULE_NAME 创建中..."
netsh advfirewall firewall add rule name=$RULE_NAME dir=in protocol=tcp action=block remoteip=$ip
}
exit

####检测频率可以调整计划任务的循环时间,单IP的并发数限制可以在第一行的‘Where-Object({$_.Count -ge 50}’  50可以自己调整
####第一次运行可能失败,是因为系统默认不允许执行powershell脚本,请输入解锁命令‘set-ExecutionPolicy RemoteSigned’即可。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值