How to test if a host's port is open?

-1

How do I find out if a particular port on a network computer is open?

The more efficient the method, the better. I'll need to scan an entire subnet several times a day.

    
asked by anonymous 23.09.2016 / 00:51

3 answers

1

Friend you can use scapy / python-nmap or socket

    
23.09.2016 / 22:31
0

The only way to know is to try to open a connection. If the port is not open your application receives an immediate response (error 1225 on Windows and 111 on Linux, corresponding to a TCP RST segment).

    
23.09.2016 / 22:35
0

Using socket :

import socket

def test_port(ip, port):
    sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
    result = sock.connect_ex((ip, port))
    sock.close()

    if result == 0:
        return True
    else:
        return False
    
08.10.2016 / 02:17