-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPythonPortScanner.py
More file actions
28 lines (21 loc) · 829 Bytes
/
PythonPortScanner.py
File metadata and controls
28 lines (21 loc) · 829 Bytes
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
import socket
import sys
# Se solicita la direccion IP
ip = input("Introduce dirección IP:")
# Se pregunta por los puertos de inicio y fin
listaPuertos = list(int(num) for num in input("Introduce el rango de puertos separados por comas:").strip().split(","))
print ("Escaneando IP {} en los puertos {} : ".format(ip,listaPuertos))
try:
for port in listaPuertos:
s = socket.socket(socket.AF_INET,socket.SOCK_STREAM)
s.settimeout(5)
if (s.connect_ex((ip,port))==0):
try:
serv = socket.getservbyport(port)
except socket.error:
error_servidor="not-found"
print(("El puerto %s:está abierto Servicio:%s "%(port,serv)))
print("Scanning Completed")
except KeyboardInterrupt as exception:
print(exception)
sys.exit()