防火墙端口超出范围

时间:2015-08-03 06:27:40

标签: c#

代码应该是正确的,但是当我运行它时,它表示端口值超出范围(我尝试了#34; 6"或者#34; 1433",这是我需要的)。谁知道什么是错的?

try
{
    INetFwRule firewallRule = (INetFwRule)Activator.CreateInstance(Type.GetTypeFromProgID("HNetCfg.FWRule"));
    firewallRule.Action = NET_FW_ACTION_.NET_FW_ACTION_ALLOW;
    firewallRule.Description = rule.Text;
    firewallRule.Enabled = true;
    firewallRule.InterfaceTypes = "All";
    firewallRule.Name = rule.Text;

    firewallRule.LocalPorts = port.Text;
    firewallRule.Protocol = (int)NET_FW_IP_PROTOCOL_.NET_FW_IP_PROTOCOL_ANY;

    INetFwPolicy2 firewallPolicy = (INetFwPolicy2)Activator.CreateInstance(
    Type.GetTypeFromProgID("HNetCfg.FwPolicy2"));
    firewallPolicy.Rules.Add(firewallRule);
}
catch (Exception ex)
{
    MessageBox.Show(ex.ToString());
}

0 个答案:

没有答案