killchain-compendium/enumeration/network_scanners/port_enum.py

36 lines
722 B
Python
Raw Normal View History

2021-08-23 01:13:54 +02:00
#!/usr/bin/env python
import sys
import socket
import pyfiglet
print(pyfiglet.figlet_format("Port Scanner"))
ip = sys.argv[1]
open_ports = []
ports = range(1,10000)
def probe_port(ip, port, result = 1):
try:
sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
sock.settimeout(0.5)
r = sock.connect_ex((ip,port))
if r == 0:
result = r
sock.close()
except Exception as e:
pass
return result
for port in ports:
sys.stdout.flush()
response = probe_port(ip, port)
if response == 0:
open_ports.append(port)
if open_ports:
print("[+] Open Ports are: ")
print(sorted(open_ports))
else:
print("[-] No Open Ports")