forked from algoritmosmathpy/algoritmos-python
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPort_Scan.py
34 lines (28 loc) · 800 Bytes
/
Port_Scan.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
"""
Algoritmo que detecta puertos abiertos en un Host Remoto
"""
#Importamos las librerias
import socket
import subprocess
import sys
from datetime import time
#Le pedimos al usuario que nos proporcione el Host Remoto
remote_server = input("Host Remoto: ")
#Obtenemos la ip del Host
remoteServerIp = socket.gethostbyname(remote_server)
try:
for port in range(1,80):
#Creamos una conexion con el Host
sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
result = sock.connect_ex((remoteServerIp, port))
if result == 0:
#Imprimimos los puertos abiertos
print("Port {}: Abierto").format(port)
sock.close()
except KeyboardInterrupt:
sys.exit()
except socket.gaierror:
sys.exit()
except socket.error:
sys.exit()
print("Escaneo completado")