腾讯云的Windows服务器防火墙,通过设置陷阱端口,屏蔽恶意访问的IP,将IP加入到腾讯云的安全组规则中,同时加入到服务器的防火墙中
unknown
2022-06-29 00ebde85aa3d586be2d2dfb755d01bf1b4b3025b
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using NetFwTypeLib;
 
namespace FirewallWindowsServer.Methods
{
    public class Test
    {
        public Test() {
            //获取防火墙实例
            INetFwPolicy2 policy2 = (INetFwPolicy2)Activator.CreateInstance(Type.GetTypeFromProgID("HNetCfg.FwPolicy2"));
 
            foreach (INetFwRule item in policy2.Rules)
            {
                if (item.Name == "TestRule") {
                    var dd = item;
                    item.RemoteAddresses = "192.168.2.111/255.255.255.255";
                }
                Console.WriteLine(item.Name);
            }
        }
    }
}