-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.py
More file actions
286 lines (253 loc) · 8.12 KB
/
main.py
File metadata and controls
286 lines (253 loc) · 8.12 KB
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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
import tkinter as tk # if not used delete it while finalizing
import ttkbootstrap as ttk
from port_scanning import Scanning
import time
from banner_grabbing import Grabbing
import threading
# hello world
def main():
global window
window = ttk.Window(
title="Socket Mapper",
size=[800, 600],
themename="superhero",
iconphoto="cable.png",
)
# Scalability | Set it false for now and change it later during optimization
window.resizable(False, False)
# The title of the running page
global title
title = ttk.Label(master=window, text="Socket Mapper", font="Jokerman 24 bold")
title.pack()
# Central image only in the main page
image = ttk.Image.open("cable.png")
image = image.resize((400, 400))
tkImage = ttk.ImageTk.PhotoImage(image)
global centralImage
centralImage = ttk.Label(master=window, image=tkImage)
centralImage.pack()
# The following buttons should navigate to two different pages
global btnFrame
btnFrame = ttk.Frame(master=window)
btnPortScanning = ttk.Button(
master=btnFrame,
text="Port Scanning",
style="success-outline",
command=Scanning_GUI,
cursor="hand2",
)
btnBannerGrapping = ttk.Button(
master=btnFrame,
text="Banner Grapping",
style="danger-outline",
command=Grabbing_GUI,
cursor="hand2",
)
btnFrame.pack(pady=20)
btnBannerGrapping.pack(side="left", padx=40)
btnPortScanning.pack(side="left", padx=40)
window.mainloop()
def clear(*args, hide=False):
for element in args:
if hide:
element.pack_forget()
else:
element.destroy()
# Try to add restoring feature in the future in order to add a back button
def Scanning_GUI():
clear(centralImage, btnFrame)
title.configure(text="Port Scanner")
# Host address or domain input box
global hostVar, hostEntryFrame
hostEntryFrame = ttk.Frame(master=window)
hostLabel = ttk.Label(master=hostEntryFrame, text="Host:", font="Chiller 18 bold")
hostVar = ttk.StringVar()
hostEntry = ttk.Entry(master=hostEntryFrame, textvariable=hostVar)
hostLabel.pack(side="left", padx=10)
hostEntry.pack(side="left", padx=10)
# Ports Range
global rangeFrame, startVar, stopVar
rangeFrame = ttk.Frame(master=window)
rangeLabel = ttk.Label(master=rangeFrame, text="Range:", font="Chiller 18 bold")
startVar = ttk.StringVar(value=0)
startEntry = ttk.Entry(
master=rangeFrame, width=5, textvariable=startVar
) # add a default value
colon = ttk.Label(master=rangeFrame, text=":", font="Chiller 24 bold")
stopVar = ttk.StringVar(value=25)
stopEntry = ttk.Entry(
master=rangeFrame, width=5, textvariable=stopVar
) # add a default value
rangeLabel.pack(side="left", padx=10)
startEntry.pack(side="left", padx=10)
colon.pack(side="left", padx=5)
stopEntry.pack(side="left", padx=10)
# TCP or UDP
global protocolVariable, protocolFrame
protocolFrame = ttk.Frame(master=window)
protocolVariable = ttk.StringVar(value="TCP") # TCP is the default value
protocolLabel = ttk.Label(
master=protocolFrame, text="Protocol:", font="Chiller 18 bold"
)
TCP_RadioButton = ttk.Radiobutton(
master=protocolFrame,
text="TCP",
variable=protocolVariable,
value="TCP",
style="Outline.Toolbutton",
)
UDP_RadioButton = ttk.Radiobutton(
master=protocolFrame,
text="UDP",
value="UDP",
variable=protocolVariable,
style="Outline.Toolbutton",
)
protocolLabel.pack(side="left", padx=10)
UDP_RadioButton.pack(side="left", padx=10)
TCP_RadioButton.pack(side="left", padx=10)
# Features
global featuresFrame, featuresLabel
featuresLabel = ttk.Label(master=window, text="Features", font="Chiller 24 bold")
featuresFrame = ttk.Frame(master=window)
# CSV... CSVT short for Comma Seprated Values Toggle button
global csVar
csVar = ttk.BooleanVar()
csvT = ttk.Checkbutton(
master=featuresFrame,
text="CSV",
style="round-toggle",
variable=csVar,
onvalue=True,
offvalue=False,
)
csvT.pack(side="left", padx=10)
# TXT
global txtVar
txtVar = ttk.BooleanVar()
txt = ttk.Checkbutton(
master=featuresFrame,
text="TXT",
style="round-toggle",
variable=txtVar,
onvalue=True,
offvalue=False,
)
txt.pack(side="left", padx=10)
# submit button
global submitBtn
submitBtn = ttk.Button(
master=window,
text="Scan",
style="outline",
command=scan,
cursor="hand2",
width=20,
)
scan_packing()
# pack the elements in the window
def scan_packing():
# here you should add the packings in ordered form
hostEntryFrame.pack(pady=20)
rangeFrame.pack(pady=20)
protocolFrame.pack(pady=20)
featuresLabel.pack(pady=20)
featuresFrame.pack()
submitBtn.pack(pady=40)
def scan():
scanner = Scanning(
host=hostVar.get(),
protocol=protocolVariable.get(),
start=int(startVar.get()),
stop=int(stopVar.get()),
txt=txtVar.get(),
csv=csVar.get(),
)
clear(
hostEntryFrame,
rangeFrame,
protocolFrame,
featuresLabel,
featuresFrame,
submitBtn,
hide=True,
)
window.after(1000, lambda: threading.Thread(target=scanner.scan(), daemon=True))
scan_packing()
# fix not responding error
def Grabbing_GUI():
clear(centralImage, btnFrame)
title.configure(text="Banner Grabber")
hostFrame = ttk.Frame(master=window)
hostLabel = ttk.Label(master=hostFrame, text="Host:", font="Chiller 18 bold")
if not "hostVar" in globals():
global hostVar
hostVar = ttk.StringVar()
hostEntry = ttk.Entry(master=hostFrame, textvariable=hostVar)
hostFrame.pack(pady=20)
hostLabel.pack(side="left", padx=10)
hostEntry.pack(side="left", padx=10)
portFrame = ttk.Frame(master=window)
portLabel = ttk.Label(master=portFrame, text="Port:", font="Chiller 18 bold")
global portVar
portVar = ttk.StringVar(value=80)
portEntry = ttk.Entry(master=portFrame, textvariable=portVar)
portFrame.pack(pady=20)
portLabel.pack(side="left", padx=10)
portEntry.pack(side="left", padx=10)
# TCP or UDP
protocolFrame = ttk.Frame(master=window)
if not "protocolVariable" in globals():
global protocolVariable
protocolVariable = ttk.StringVar(value="TCP") # TCP is the default value
protocolLabel = ttk.Label(
master=protocolFrame, text="Protocol:", font="Chiller 18 bold"
)
TCP_RadioButton = ttk.Radiobutton(
master=protocolFrame,
text="TCP",
variable=protocolVariable,
value="TCP",
style="Outline.Toolbutton",
)
UDP_RadioButton = ttk.Radiobutton(
master=protocolFrame,
text="UDP",
value="UDP",
variable=protocolVariable,
style="Outline.Toolbutton",
)
protocolFrame.pack(pady=20)
protocolLabel.pack(side="left", padx=10)
UDP_RadioButton.pack(side="left", padx=10)
TCP_RadioButton.pack(side="left", padx=10)
if not "txtVar" in globals():
global txtVar
txtVar = ttk.BooleanVar()
txt = ttk.Checkbutton(
master=window,
text="TXT",
style="round-toggle",
variable=txtVar,
onvalue=True,
offvalue=False,
)
txt.pack()
# submission button
submit = ttk.Button(
window, text="Grab", style="outline", command=grab, width=20, cursor="hand2"
)
submit.pack(side="bottom", pady=40)
def grab():
grabber = Grabbing(hostVar.get(), int(portVar.get()), protocolVariable.get())
if txtVar.get():
window.after(
1000, lambda: threading.Thread(target=grabber.save(), daemon=True).start()
)
else:
window.after(
1000, lambda: threading.Thread(target=print(grabber.grab()), daemon=True).start()
) # make it in the gui later
if __name__ == "__main__":
main()
# Do some bug fixes!!