-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathportscanner-v2-threaded.py
77 lines (60 loc) · 2.15 KB
/
portscanner-v2-threaded.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
77
import sys
import socket
import pyfiglet
import threading
import time
from queue import Queue
## Threading is still very confusing to me. It took a lot of messy, failed compiles to get this working.
## and a lot of help from py-oneers that paved the way.
## Will get to making a v3 and will push into multi-core technology utilization for an even faster portscan
# v1 was DAVID BANNER, v2 is regular simp hulk, v3 will alight the skies as devious-dummy RED HULK will heat your CPUs and violate your heat sinks
# no apologies on my end either. you wanted the education, so pay for the computer reparations, big boy! scumdestroy outta here!!
## thanks for reading!
bannerscanner = pyfiglet.figlet_format(".PORTSMASHER.")
bannerscanner2 = pyfiglet.figlet_format("..HULKRASHER..")
print(bannerscanner)
print(bannerscanner2)
# translate to IPv4 in case hostname was input in a foolish way
target = socket.gethostbyname(sys.argv[1])
socket.setdefaulttimeout(1)
print("READING TARGET...")
print("*WHIRR*... BEEP...YES")
print("I FIND THE TARGET ACCEPTABLE. PORT MOLESTATION MAY NOW BEGIN.")
# CHECKIN ALL THEM PORTS, quick, stick, n, we skip (to the next one)
def portscan(port):
try:
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
# and so we not hanging forever...
result = s.connect((target, port))
# don't let thread contention screw up printing
print('{} is open'.format(port))
if result == 0:
s.close()
except:
pass
# threader thread pulls worker from queue and processes
def threader():
while True:
# gets worker from queue
worker = q.get()
# run job with savailable worker in queue (thread)
portscan(worker)
# complete with the job, shut down thread?
q.task_done()
q = Queue()
#start tie
startTime = time.time()
for x in range(66):
#Thread ID
t = threading.Thread(target = threader)
#classify as daemon, so they die when main dies
t.daemon = True
#begins - must come after daemon definition
t.start()
for worker in range(1,65535):
q.put(worker)
#wait til termination
q.join()
# ok, give us a final time report
runtime = float("%0.2f" % (time.time() - startTime))
print("Run Time: ", runtime, "seconds")