This python script specifically works for checking for open ports on a targeting IP address with the use of the socket library. It could assist a network administrator in determining services that have been exposed on the network.
Code Example:
`import socket
def scan_ports(target, ports):
for port in ports:
with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as s:
s.settimeout(1)
if s.connect_ex((target, port)) == 0:
print(f"Port {port} is open")
target = "127.0.0.1"
ports = range(20, 1025)
scan_ports(target, ports)
`
Use Case: The script is helpful to conduct network security penetration tests in order to give recommendations on open ports that are susceptible to acts by malicious personnel. It can also be used for the intern testing of the firewalls or services amongst staff.
Tip: Remember that port scanners should be run on networks that you are authorized to scan as using scanner on other networks maybe unlawful.
Top comments (0)