Click here to Skip to main content
15,887,485 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:

How do you know https(8443) port is open

How do you know ftp port is open
Posted

you don't have to write code to check whether a port is open or not. you can use telnet application:

telnet localhost 21


But if you need to check it in code, you can use TcpClient:

C#
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net.Sockets;
using System.Text;
using System.Threading.Tasks;

namespace Test_TcpConnect
{
    class Program
    {
        static void Main(string[] args)
        {
            try
            {
                using (TcpClient cl = new TcpClient("localhost", 21))
                {
                    Console.WriteLine("connected");
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex);
            }
        }
    }
}
 
Share this answer
 
try this.
C#
bool IsOpen(int port)
{
IPGlobalProperties Properties = IPGlobalProperties.GetIPGlobalProperties();
IPEndPoint[] EndPoints = Properties.GetActiveTcpListeners();
foreach (IPEndPoint i in EndPoints)
{
if (i.Port == port)
return true;
}
return false;
}
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900