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.
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.
Friend you can use scapy / python-nmap or socket
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).
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