Lab15: Python| Scanning Metasploitable Host for Open Ports with Python Socket Module| Cyber Security

Опубликовано: 20 Февраль 2026
на канале: Learn With Rubel
418
3

Define the Python socket module:
The Python socket module lets programmers connect their Python programs to networks. With sockets, Python apps can send and receive data over networks using TCP or UDP. It helps create, address, and manage connections, and handle errors. This makes it easy to build all sorts of networked apps, from simple chat programs to big, complex systems.
---------------------------------------------------------------------------------------------------------------------
import socket

metaServer = input("Enter a Metasploitable host to scan: ")
metaServerIP = socket.gethostbyname(metaServer)
print(metaServerIP)

print("-" * 60)
print("Please wait, Scanning Metasploitable host", metaServerIP)
print("-" * 60)

for port in range(1, 100):
sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
result = sock.connect_ex((metaServerIP, port))
if result == 0:
print("Port {}: Open".format(port))
sock.close()
---------------------------------------------------------------------------------------------------------------------








#Networking, #CCNA, #CCNP, #linux, #AWS, #InformationTechnology, #ITCertification, #raspberry pi, #ethicalhacking