-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathp0rtsc4n.py
59 lines (45 loc) · 1.35 KB
/
p0rtsc4n.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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
# @AUTHOR: 4N4NR0
import sys
import socket
import pyfiglet
from colorama import init, Fore, Back
def banner(titel):
init()
print(Fore.RED+"*"*53+Fore.RESET)
print(13*"-"+"\tCREATED BY 4N4RCH0\t"+"-"*13)
print(Back.BLACK+Fore.RED+pyfiglet.figlet_format(titel, font="avatar")+Back.RESET+Fore.RESET)
print(Fore.RED+"*"*53+Fore.RESET)
banner(" P0RTSC4N")
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
ip = input("[?] Target host/ip address: ")
print("\n"+"_"*53)
open_ports = []
ports = range(1, 65535)
try:
for port in ports:
sys.stdout.flush()
response = probe_port(ip, port)
if response == 0:
print(Fore.GREEN+f"[ + ] IP {ip}\tPORT {str(port)} - OPEN"+Fore.RESET)
open_ports.append(port)
else:
print(Fore.RED+f"[ - ] IP {ip}\tPORT {str(port)} - CLOSED"+Fore.RESET)
if open_ports:
print("[ + ] Open Ports: ")
print(sorted(open_ports))
else:
print("[ - ] No open ports discovered.")
except KeyboardInterrupt:
sys.exit()
except Exception as e:
print(f"[ERROR]\t{e}")