c++ - 判断IP是否被封

标签 c++ windows security networking

有谁知道是否可以可靠地确定(以编程方式 C/C++...)Windows PC 上是否安装了防火墙或 IP 过滤软件?我需要检测客户端软件中的某个服务器IP是否被主机操作系统阻止。

在这种情况下我不需要担心外部硬件防火墙,因为我可以完全控制它。我只关心软件防火墙。我希望能够迭代 Windows 网络堆栈或 NDIS 接口(interface)并确定这一点

最佳答案

在阅读了您回复其他答案的一些评论后,我认为这实际上可能更接近您正在寻找的内容。它可能无法捕获所有类型的防火墙,但任何主要的防火墙供应商都应在安全中心注册,因此可以使用此方法进行检测。您还可以将此与此处的其他一些答案结合起来,为自己提供第二级验证。

Detecting running firewalls in windows

这是专家的交流帖子,因此您可能无法阅读该帖子。以防万一,我复制并粘贴了相关信息。它是用 VBScript 编写的,但它应该为您指明可以使用哪些 WMI 命名空间的正确方向。

KemalRouge: I've just solved this problem with some help from a colleague. He pointed me in the direction of a knowledge base article, which pointed out that this information was stored in the WMI database

Basically, it's possible to query the WMI in a few lines of code to find out what firewalls/anti-virus software is being monitored by the Security Center, and the status of this software (i.e. enabled or not).

Anyway, if you're interested, here's some VB code I used to test this out (you'll need a reference to "Microsoft WMI Scripting V1.2 Library"):

Private Sub DumpFirewallInfo()

Dim oLocator    As WbemScripting.SWbemLocator
Dim oService    As WbemScripting.SWbemServicesEx
Dim oFirewalls  As WbemScripting.SWbemObjectSet
Dim oFirewall   As WbemScripting.SWbemObjectEx
Dim oFwMgr      As Variant
   
   
    Set oFwMgr = CreateObject("HNetCfg.FwMgr")
   
    Debug.Print "Checking the Windows Firewall..."
    Debug.Print "Windows Firewal Enabled: " & oFwMgr.LocalPolicy.CurrentProfile.FirewallEnabled
    Debug.Print ""
   
    Set oFwMgr = Nothing
   
   
    Debug.Print "Checking for other installed firewalls..."
   
    Set oLocator = New WbemScripting.SWbemLocator
    Set oService = oLocator.ConnectServer(".", "root\SecurityCenter")
    oService.Security_.ImpersonationLevel = 3

    Set oFirewalls = oService.ExecQuery("SELECT * FROM FirewallProduct") ' This could also be "AntivirusProduct"
   
    For Each oFirewall In oFirewalls
        Debug.Print "Company:       " & vbTab & oFirewall.CompanyName
        Debug.Print "Firewall Name: " & vbTab & oFirewall.DisplayName
        Debug.Print "Enabled:       " & vbTab & Format$(oFirewall.Enabled)
        Debug.Print "Version:       " & vbTab & oFirewall.versionNumber
        Debug.Print ""
    Next oFirewall
   
    Set oFirewall = Nothing
    Set oFirewalls = Nothing
    Set oService = Nothing
    Set oLocator = Nothing

End Sub

关于c++ - 判断IP是否被封,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/198625/

相关文章:

windows - 使用cx_Freeze、PyQt5、Python3构建的exe无法导入ExtensionLoader_PyQt5_QtWidgets.py并运行

linux - 如何在 Linux 上为 IdentityServer4 配置 key

linux - 用于清除 .bash_history 中的密码的脚本或单行代码

C++ 行和列矩阵操作

c++ - WSAENOBUFS 和 WSAEWOULDBLOCK 有什么区别?

c# - 当使用管理包装器取消管理 C++ DLL 时,.net 是否创建任何临时 C# 文件

c - 进程的内存地址空间

windows - `cleartool lsco -r -cvi -me` 与 `cleartool lsco -graphical` 相比非常慢。是否有可能提高它的性能?

.net - WCF 身份验证

c++ - 使用 int() 进行变量初始化