-
Notifications
You must be signed in to change notification settings - Fork 1
/
scanner_nocolorama.py
executable file
·75 lines (71 loc) · 3.04 KB
/
scanner_nocolorama.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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
#!/usr/bin/python3
#a huge thank you and shoutout to stackoverflow my lord and savior <3
#feel free to clone this and use it during your CTF adventures.
import socket, sys, threading
from os import system, name
verbosity = 0
def clear():
if name == 'nt':
system('cls')
else:
system('clear')
def portscan(ip_addr,port):
sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
result = sock.connect_ex((ip_addr, port))
if result == 0:
print(f"Port {port} open on {ip_addr}")
sock.close()
else:
if verbosity == 1:
print(f"[+] Port {port} closed on {ip_addr}")
sock.close()
def beginScan(ip_addr,port_start,port_end,multihost_flag):
if multihost_flag == 0:
if verbosity == 1:
print(f"[+] Singlehost Mode Selected")
print(f"[+] Scanning Host: {ip_addr}")
if verbosity == 1:
print(f"[+] Beginning Scan.")
for port in range(int(port_start), int(port_end) + 1):
t = threading.Thread(target=portscan,args=(ip_addr,port))
t.start()
t.join()
print(f"[+] Scan on host {ip_addr} complete.")
elif multihost_flag == 1:
if verbosity == 1:
print(f"[+] Multihost Mode Selected")
for host_portion in range (1,255):
ip_addr_m = ip_addr + "." + str(host_portion)
print(f"[+] Scanning {ip_addr_m} in range {ip_addr}.1/24")
if verbosity == 1:
print(f"[+] Beginning Scan.")
for port in range(int(port_start), int(port_end) + 1):
t = threading.Thread(target=portscan,args=(ip_addr_m,port))
t.start()
t.join()
print(f"[+] Scan on host {ip_addr_m} complete.")
if __name__ == '__main__':
socket.setdefaulttimeout(1)
if sys.argv.__contains__("-v"):
verbosity = 1
if sys.argv.__contains__("-h"):
clear()
print(f"[+] Usage:\n[*] Verbosity: -v\n[*] Single Host Scan: -s\n [-] e.g ./scanner.py <ip> <port_start> <port_end> -s\n [-] e.g ./scanner.py 10.1.1.1 1 65535 -s\n[*] Scan Multiple Hosts: -m\n [-] e.g ./scanner.py <ip up to host portion> <port_start> <port_end> -m\n [-] e.g ./scanner.py 10.1.1 1 65535 -m\n[*] Help: -h\n [-] e.g ./scanner.py -h\n")
quit()
if len(sys.argv) <= 6:
if sys.argv.__contains__("-s"):
multihost_flag = 0
ip_addr = sys.argv[1]
port_start = sys.argv[2]
port_end = sys.argv[3]
beginScan(ip_addr,port_start,port_end,multihost_flag)
elif sys.argv.__contains__("-m"):
multihost_flag = 1
ip_addr = sys.argv[1]
port_start = sys.argv[2]
port_end = sys.argv[3]
beginScan(ip_addr,port_start,port_end,multihost_flag)
else:
clear()
print(f"[+] Usage example: ./scanner.py <ip> <port_start> <port_end> \n[+] Use tag -h for more information.\n")
#print(f" [+] DEBUG SCANNING {ip_addr} FROM {int(port_start)} TO {int(port_end)}")