标签:80端口 检测 c#
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端口 检测 c#
原文地址:http://wongcony.blog.51cto.com/7188824/1545216