How to create a network scanner in python using
socket library is used to work with network and here we use it to simulate a network scanner.
A network scanner iterates over all the possible IP addresses on the network and for every IP it tries to connect to one of the ports. If the connection was successful (ACK received) we know that this host is available at the given IP address. This is the philosophy of a network scanner.
For now we just try to connect to a specific port of the server and leave the other parts to you to iterate and check the status:
The above code connects to the given
port is open otherwise the port is probably blocked/closed.
#python #socket #network #tcp #tcp_scanner
socket
?socket library is used to work with network and here we use it to simulate a network scanner.
A network scanner iterates over all the possible IP addresses on the network and for every IP it tries to connect to one of the ports. If the connection was successful (ACK received) we know that this host is available at the given IP address. This is the philosophy of a network scanner.
For now we just try to connect to a specific port of the server and leave the other parts to you to iterate and check the status:
import socket
addr = '172.16.132.20'
port = 27017
socket_obj = socket.socket(socket.AF_INET,socket.SOCK_STREAM)
socket.setdefaulttimeout(1)
result = socket_obj.connect_ex((addr,port))
print result
socket_obj.close()
The above code connects to the given
address:port
and returns a status code. If returned code is 0 then theport is open otherwise the port is probably blocked/closed.
#python #socket #network #tcp #tcp_scanner