您的位置:首页 > 编程语言 > C#

C#检测端口是否被占用(转帖)

2009-06-08 15:21 549 查看
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");
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: