检测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端口打开!", "提示");

            }

        }