首页 > 代码库 > 检测80端口是否开启
检测80端口是否开启
public static void port_check(string ip)
{
bool tcpListen = false;
bool udpListen = false;//设定端口状态标识位
string ip_str = ip;
System.Net.IPAddress myIpAddress = IPAddress.Parse(ip_str);
System.Net.IPEndPoint myIpEndPoint = new IPEndPoint(myIpAddress, 80);
try
{
System.Net.Sockets.TcpClient tcpClient = new TcpClient();
tcpClient.Connect(myIpEndPoint);//对远程计算机的指定端口提出TCP连接请求
tcpListen = true;
}
catch { }
try
{
System.Net.Sockets.UdpClient udpClient = new UdpClient();
udpClient.Connect(myIpEndPoint);//对远程计算机的指定端口提出UDP连接请求
udpListen = true;
}
catch { }
if (tcpListen == false && udpListen == false)
{
Console.WriteLine("80端口关闭!", "提示");
}
else
{
Console.WriteLine("80端口打开!", "提示");
}
}
本文出自 “牧尹御林” 博客,请务必保留此出处http://wongcony.blog.51cto.com/7188824/1545216
检测80端口是否开启