-
Notifications
You must be signed in to change notification settings - Fork 0
/
Fast_Port_Scanner.py
76 lines (55 loc) · 1.77 KB
/
Fast_Port_Scanner.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
76
import pyfiglet
import socket
import threading
import concurrent.futures
import datetime
import argparse
parser = argparse.ArgumentParser(prog='fast.py', usage='%(prog)s [Target] [Port]',epilog="Example: fast.py google.com 1-10000 fast.py github.com all ")
parser.add_argument("target", help = "[target ip]")
parser.add_argument("port", help = "[port] (default = 1-1000)",default=1, nargs = '?')
args = parser.parse_args()
ip=args.target
nport=args.port
if nport==1:
start=1
end=1000
elif nport== "all":
start=1
end=65535
else:
start,end= nport.split("-")
start= int(start)
end= int(end)
print("-" * 70)
print("github.com/DoguhanPOLAT")
ascii_banner = pyfiglet.figlet_format("PORT SCANNER")
print(ascii_banner)
def date_time():
return datetime.datetime.now().strftime("%d/%m/%Y %H:%M:%S")
print_lock = threading.Lock()
# translate hostname to IPv4
targetip = socket.gethostbyname(ip)
# For information
print("-" * 70)
print("Scanning Target - {} ({})".format(ip,targetip))
print("Scan started - [{}]".format(date_time()))
print("-" * 70)
print("\n Ip\t\tPort\t\tState")
print("-" * 55)
#Scaning
def scan(ip,port):
scanner= socket.socket(socket.AF_INET, socket.SOCK_STREAM)
scanner.settimeout(1)
try:
scanner.connect((ip,port))
scanner.close()
with print_lock:
print("{}\t\t{}\t\tOpen".format(targetip,port))
except:
pass
with concurrent.futures.ThreadPoolExecutor(max_workers=100) as executor:
# will scan ports between 1 to 65,535
for port in range(start,end):
executor.submit(scan, ip, port + 1)
print("\nScan finished - [{}]".format(date_time()))
print("-" * 70)