如何通过.NET 3.5中的NT防火墙打开TCP/UDP端口 [英] how to open TCP/UDP ports through NT firewall in .NET 3.5

查看:123
本文介绍了如何通过.NET 3.5中的NT防火墙打开TCP/UDP端口的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要编写一个.NET程序以通过NT防火墙打开端口.协议(UDP或TCP)和端口号将由用户作为输入传递.

I need to write a .NET program to open ports through the NT firewall. Protocol (UDP or TCP) and port number will be passed by user as input.

推荐答案

另一种方法是使用netsh命令.您可以使用Process.Start将其作为一个进程启动.

Another way to do this is to use the netsh command. You would launch it as a process using Process.Start. This works on XP and Windows 7 (I assume Vista also because it works on 7).

 例如,如果要打开UDP端口20502,则netsh命令为:

 For example, if you wanted to open UDP port 20502, the netsh command would be:

netsh防火墙添加打开UDP 20502 UserFriendlyName的端口全部启用

 netsh firewall add portopening UDP 20502 UserFriendlyName ENABLE ALL

 并且,如果您要关闭端口:

 And, if you wanted to close the port:

netsh防火墙删除打开UDP 20502 ALL的端口

netsh firewall delete portopening UDP 20502 ALL

 

如果要向防火墙添加程序例外:

If you want to add a program exception to the firewall:

netsh防火墙,请添加允许的程序"c:\ program files \ your folder \ your.exe" UserFriendlyName

netsh firewall add allowedprogram "c:\program files\your folder\your.exe" UserFriendlyName

如果要从防火墙中删除程序例外:

If you want to remove a program exception from the firewall: 

netsh防火墙,请删除允许的程序"c:\ program files \ your folder \ your.exe"

netsh firewall delete allowedprogram "c:\program files\your folder\your.exe"


看看UdpClientTcpClient类.需要手动配置防火墙,以允许使用您要使用的端口.
Have a look at the UdpClient and TcpClient classes.  The firewall needs to be configured manually to allow the ports that you want to use.


这篇关于如何通过.NET 3.5中的NT防火墙打开TCP/UDP端口的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆