-
Notifications
You must be signed in to change notification settings - Fork 0
/
portscanner.py
50 lines (38 loc) · 2.06 KB
/
portscanner.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
import socket
import termcolor
termcolor.cprint("""192.168.86.1
_______ _______ _______ _________ _______ _______ _______ _ _ _______ _______
( ____ )( ___ )( ____ )\__ __/( ____ \( ____ \( ___ )( ( /|( ( /|( ____ \( ____ )
| ( )|| ( ) || ( )| ) ( | ( \/| ( \/| ( ) || \ ( || \ ( || ( \/| ( )|
| (____)|| | | || (____)| | | | (_____ | | | (___) || \ | || \ | || (__ | (____)|
| _____)| | | || __) | | (_____ )| | | ___ || (\ \) || (\ \) || __) | __)
| ( | | | || (\ ( | | ) || | | ( ) || | \ || | \ || ( | (\ (
| ) | (___) || ) \ \__ | | /\____) || (____/\| ) ( || ) \ || ) \ || (____/\| ) \ \__
|/ (_______)|/ \__/ )_( \_______)(_______/|/ \||/ )_)|/ )_)(_______/|/ \__/
""", 'cyan')
def scan(target, ports):
termcolor.cprint('\n' + '[!] Starting Scan For ' + str(target), 'magenta')
for port in range(1,ports):
scan_port(target,port)
def scan_port(ipaddress, port):
try:
sock = socket.socket()
sock.connect((ipaddress, port))
termcolor.cprint(f"[+] Port {port} Opened " , 'green')
sock.close()
except:
if cleanmode.lower() == 'n':
termcolor.cprint(f"[-] Port {port} Closed " , 'red')
sock.close()
elif cleanmode.lower() == 'y':
pass
targets = input(termcolor.colored("[*] Enter Targets To Scan (Split targets with comma) >> " , 'blue'))
ports = int(input(termcolor.colored("[*] Enter How Many Ports You Want To Scan (MAX is 65,535) >> ", 'blue')))
cleanmode = input(termcolor.colored("[*] Would you like a clean output? (y/n) >> ", 'blue'))
if ',' in targets:
print(termcolor.colored(("[#] Scanning Multiple Targets"), 'yellow'))
for ip_addr in targets.split(','):
scan(ip_addr.strip(' '), ports)
else:
scan(targets,ports)
termcolor.cprint("[*] Scan finished. Please run program again to do another scan.", "yellow")