【发布时间】:2015-05-30 12:19:17
【问题描述】:
我需要在域网络防火墙中为我的应用程序打开特定端口。
我试过这段代码:
INetFwOpenPorts ports;
INetFwOpenPort port = (INetFwOpenPort)Activator.CreateInstance(
Type.GetTypeFromProgID("HNetCfg.FWOpenPort")); ;
port.Port = 8000; /* port no */
port.Name = "Application1"; /*name of the application using the port */
port.Enabled = true; /* enable the port */
port.Scope = NetFwTypeLib.NET_FW_SCOPE_.NET_FW_SCOPE_ALL;
port.Protocol = NetFwTypeLib.NET_FW_IP_PROTOCOL_.NET_FW_IP_PROTOCOL_UDP;//.NET_FW_IP_PROTOCO L_TCP;
Type NetFwMgrType = Type.GetTypeFromProgID("HNetCfg.FwMgr", false);
INetFwMgr mgr = (INetFwMgr)Activator.CreateInstance(NetFwMgrType);
ports = (INetFwOpenPorts)mgr.LocalPolicy.CurrentProfile.GloballyOpenPorts;
ports.Add(port);
但它不起作用!在 Windows 防火墙中的域网络打开之前,我的数据不会发送!
【问题讨论】:
标签: c# network-programming windows-8.1 windows-firewall