#region 检测端口号
public bool CheckPort(string tempPort)
{
Process p = new Process();
p.StartInfo = new ProcessStartInfo("netstat", "-an");
p.StartInfo.CreateNoWindow = true;
p.StartInfo.UseShellExecute = false;
p.StartInfo.WindowStyle = ProcessWindowStyle.Hidden;
p.StartInfo.RedirectStandardOutput = true;
p.Start();
string result = p.StandardOutput.ReadToEnd().ToLower();//最后都转换成小写字母
System.Net.IPAddress[] addressList = Dns.GetHostByName(Dns.GetHostName()).AddressList;
List<string> ipList = new List<string>();
ipList.Add("127.0.0.1");
ipList.Add("0.0.0.0");
for (int i = 0; i < addressList.Length; i++)
{
ipList.Add(addressList[i].ToString());
}
bool use = false;
for (int i = 0; i < ipList.Count; i++)
{
if (result.IndexOf("tcp " + ipList[i] + ":" + tempPort) >= 0 || result.IndexOf("udp " + ipList[i] + ":" + tempPort) >= 0)
{
use = true;
break;
}
}
p.Close();
return use;
}
#endregion