110,533
社区成员
发帖
与我相关
我的任务
分享
private void button3_Click(object sender, EventArgs e)
{
Process p = new Process();
p.StartInfo = new ProcessStartInfo("netstat", "-a");
p.StartInfo.UseShellExecute = false;
p.StartInfo.RedirectStandardOutput = true;
p.StartInfo.CreateNoWindow = true; //设置不显示DOS窗口
p.Start();
string result = p.StandardOutput.ReadToEnd();
for (int i = 4000; i <= 8000; i++)
{
if (result.IndexOf(Environment.MachineName.ToLower() + ":" + i) >= 0) MessageBox.Show(i + "端口被占用");
//if (result.IndexOf(Environment.MachineName.ToLower() + ":" + i) == -1) MessageBox.Show(i + "端口没被占用");
}
}