C#winform中使用动态udp端口,在程序中怎么判断udp端口是否打开? 我想在C#winform中使用动态udp端口,在程序中怎么判断udp端口是否打开?或者说让程序先作判断某个端口已经被占用了,如果被占用就使用其它未被占用的端口? 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 or利用.Net中Process类调用netstat命令来判断计算端口的使用情况: Process p = new Process();p.StartInfo = new ProcessStartInfo("netstat", "-a");p.StartInfo.CreateNoWindow = true;p.StartInfo.UseShellExecute = false;p.StartInfo.WindowStyle = ProcessWindowStyle.Hidden;p.StartInfo.RedirectStandardOutput = true;p.Start();string result = p.StandardOutput.ReadToEnd();if (result.IndexOf(Environment.MachineName.ToLower() + ":4000") >= 0)MessageBox.Show("4000端口被占用");else{MessageBox.Show("ok");} Process p=new Process(); p.StartInfo=new ProcessStartInfo( "netstat ", "-a "); TcpClient tcp = new TcpClient(); tcp.Connect(hostName,port); .resx 文件 图片资源丢失(该资源文件名的话文件名会自动恢复) .net在没有安装word的程序上读取word 小弟初学者,有个疑问。。还望指点。。 C# 程序的问题. C#如何制作这个??? menu 菜单中子窗体与主窗体的问题,急!! 在FORM窗口中调用API创建子窗口,却总是显示不出来,这是为什么 建立本地的SQLServer连接时是否要先建立一个ODBC数据源? 类型转换问题 C#中获得时间的问题???? 操作ACCESS数据库、DataTable VS2008 的treeview 有Columns属性吗?
Process p = new Process();
p.StartInfo = new ProcessStartInfo("netstat", "-a");
p.StartInfo.CreateNoWindow = true;
p.StartInfo.UseShellExecute = false;
p.StartInfo.WindowStyle = ProcessWindowStyle.Hidden;
p.StartInfo.RedirectStandardOutput = true;
p.Start();
string result = p.StandardOutput.ReadToEnd();
if (result.IndexOf(Environment.MachineName.ToLower() + ":4000") >= 0)
MessageBox.Show("4000端口被占用");
else
{
MessageBox.Show("ok");
}
p.StartInfo=new ProcessStartInfo( "netstat ", "-a ");
tcp.Connect(hostName,port);