惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

博客园 - 三生石上(FineUI控件)
Hugging Face - Blog
Hugging Face - Blog
M
MIT News - Artificial intelligence
T
Tailwind CSS Blog
Webroot Blog
Webroot Blog
S
Secure Thoughts
N
News and Events Feed by Topic
月光博客
月光博客
TaoSecurity Blog
TaoSecurity Blog
Microsoft Azure Blog
Microsoft Azure Blog
B
Blog RSS Feed
N
News | PayPal Newsroom
Exploit-DB.com RSS Feed
Exploit-DB.com RSS Feed
小众软件
小众软件
Recent Commits to openclaw:main
Recent Commits to openclaw:main
P
Privacy & Cybersecurity Law Blog
GbyAI
GbyAI
K
Kaspersky official blog
WordPress大学
WordPress大学
P
Proofpoint News Feed
cs.CV updates on arXiv.org
cs.CV updates on arXiv.org
博客园 - 叶小钗
W
WeLiveSecurity
Jina AI
Jina AI
The Cloudflare Blog
Project Zero
Project Zero
Simon Willison's Weblog
Simon Willison's Weblog
V
Vulnerabilities – Threatpost
L
LangChain Blog
Forbes - Security
Forbes - Security
PCI Perspectives
PCI Perspectives
Engineering at Meta
Engineering at Meta
Google DeepMind News
Google DeepMind News
Recorded Future
Recorded Future
博客园 - 【当耐特】
H
Heimdal Security Blog
A
About on SuperTechFans
Cisco Talos Blog
Cisco Talos Blog
T
Threat Research - Cisco Blogs
云风的 BLOG
云风的 BLOG
Spread Privacy
Spread Privacy
L
LINUX DO - 最新话题
L
Lohrmann on Cybersecurity
Last Week in AI
Last Week in AI
Google DeepMind News
Google DeepMind News
CTFtime.org: upcoming CTF events
CTFtime.org: upcoming CTF events
I
Intezer
Martin Fowler
Martin Fowler
S
Securelist
Threat Intelligence Blog | Flashpoint
Threat Intelligence Blog | Flashpoint

博客园 - WmW

C#学习牛顿迭代法开方 mysql将一个表中指定时间之后的新数据导入到另一个表中 使用具体时间和DateTime.Now运算时需要注意DateTime.Now的毫秒数 简单搭建一个 ASP.NET Core Web API + Mysql + SqlSugar demo项目 C# 学习研究CRC校验 C# 学习逆变和协变 C# 标准的Dispose模式 C# 返回Task或者Task<T>的方法中如果没有异步方法,就没必要使用async修饰 关于字节序的概念加深 C# 基于ReadOnlySequence和ReadOnlySequenceSegment的简单封装 简单接触BCD码,以及使用C#简单实现BCD转换 C# ReadOnlySequence和ReadOnlySequenceSegment简单使用 C# 非常简单的文字转语音实现 C# 输出年龄和属相列表 C# 封装了一个用来对参数值进行范围限制的泛型方法 C# 将Framework4.8控制台程序注册为windows服务 C# async void 方法中使用await时外部不会等待 C# Channel学习 C# 使用字符串分割字符串 C# 一个简单的连续心率血氧压缩算法 C# 将日期时间按照ISO 8601标准转成字符串 Dapper传递参数对象时,只支持属性,无法解析字段(出现Parameter '?id' must be defined)
C# 为WindowsDefender防火墙已经存在的入站规则添加IP地址
WmW · 2025-02-24 · via 博客园 - WmW
    /// <summary>
    /// windows防火墙入站规则IP添加器
    /// </summary>
    internal class NetFwRuleIPAdder {
        readonly string ruleName;
        readonly object _lock = new object();
        /// <summary>
        /// 创建一个添加器,可以将指定IP添加到ruleName规则中
        /// </summary>
        /// <param name="ruleName">规则名称</param> 
        public NetFwRuleIPAdder(string ruleName) {
            this.ruleName = ruleName;
        }
        /// <summary>
        /// 获取规则对象
        /// </summary>
        INetFwRule GetNetFwRule() {
            INetFwRule netFwRule = null;
            INetFwPolicy2 netFwPolicy2 = (INetFwPolicy2)Activator.CreateInstance(Type.GetTypeFromProgID("HNetCfg.FwPolicy2"));
            foreach (INetFwRule rule in netFwPolicy2.Rules) {
                if (rule.Name == ruleName && rule.Direction == NET_FW_RULE_DIRECTION_.NET_FW_RULE_DIR_IN) { //匹配规则名和入站规则
                    netFwRule = rule;
                    break;
                }
            }
            if (netFwRule == null) {
                throw new Exception("未匹配到:" + ruleName + ",请先手动创建该规则");
            }
            return netFwRule;
        }
        /// <summary>
        /// 向当前防火墙规则中添加IP
        /// </summary>
        public void AddIP(string ip) {
            lock (_lock) {
                var netFwRule = GetNetFwRule();
                if (string.IsNullOrEmpty(netFwRule.RemoteAddresses)) {
                    netFwRule.RemoteAddresses = ip;
                } else {
                    if (netFwRule.RemoteAddresses.Split(',').Contains(ip) == false) {
                        netFwRule.RemoteAddresses = netFwRule.RemoteAddresses + "," + ip;
                    }
                }
                LogHelper.Info(ip + " 添加完毕");
            }
        }
    }

posted @ 2025-02-24 11:33  WmW  阅读(123)  评论()    收藏  举报