1
I created a Scan Port in C# (winforms), which is checking a range of ports, previously set, I can verify that the door is open, but my problem is this: I know the door is open, but I don’t know what kind of service is running on that door, there is some function or library that I can verify which service is running on these open doors??
public void StartScan(object o)
{
    IPAddress ipAddress = o as IPAddress;
    gridPortaAberta.Rows.Clear();
    for (int i = startPort; i <= endPort; i++)
    {
        lock (consoleLock)
        {
            label5.Text = "Scaneando Porta: " + i;
        }
        while (waitingForResponses >= maxQueriesAtOneTime)
            Thread.Sleep(0);
        if (stop)
            break;
        try
        {
            Socket s = new Socket(AddressFamily.InterNetwork,
                                  SocketType.Stream, ProtocolType.Tcp);
            //Representa um ponto de extremidade de rede como um endereço IP e um número de porta.
            s.BeginConnect(new IPEndPoint(ipAddress, i), EndConnect, s);
            Interlocked.Increment(ref waitingForResponses);
        }
        catch (Exception)
        {
        }
    }
}
public void EndConnect(IAsyncResult ar)
{
    try
    {
        DecrementResponses();
        List<string> items = new List<string>();
        Socket s = ar.AsyncState as Socket;
        s.EndConnect(ar);
        if (s.Connected)
        {
            int openPort = Convert.ToInt32(s.RemoteEndPoint.ToString().Split(':')[1]);
            openPorts.Add(openPort);
            gridPortaAberta.Rows.Add(openPort.ToString());
            lock (consoleLock)
            {
                Console.WriteLine("TCP conectado na porta: { 0}", openPort);
            }
            s.Disconnect(true);
        }
    }
    catch (Exception)
    {
    }
}
public void IncrementResponses()
{
    Interlocked.Increment(ref waitingForResponses);
    PrintWaitingForResponses();
}
public void DecrementResponses()
{
    Interlocked.Decrement(ref waitingForResponses);
    PrintWaitingForResponses();
}
public void PrintWaitingForResponses()
{
    lock (consoleLock)
    {
        label6.Text = "Esperando respostas de " + waitingForResponses + " threads";
    }
}
						
if you can show the code you are working on... help
– Rovann Linhalis
I posted the code friend, sera q there is some way to make this check??
– cleiton
You’re basically trying to connect to the door... if it goes wrong, it’s because you’re being used. I recommend viewing this code, use the windows executable to read the ports and you can get more information: http://www.cheynewallace.com/get-active-ports-and-associated-process-names-in-c/
– Rovann Linhalis
there is this other way by doing the application by hand using the windows API: https://www.codeproject.com/Articles/4298/Getting-active-TCP-UDP-connections-on-a-box
– Rovann Linhalis
obg friend, I saw the projects here, I think it will give right to what I need, very obggg
– cleiton