-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsweeper.py
More file actions
73 lines (54 loc) · 1.45 KB
/
sweeper.py
File metadata and controls
73 lines (54 loc) · 1.45 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
# -*- coding: utf-8 -*-
#%%
import os
import queue
import threading
import time
import tkinter as tk
import socket
#TODO: add port scan
#TODO: make printout in order
def ping(ip_address):
command = "ping -n 1 -w 800 "
response = os.popen(command + ip_address)
lines = response.readlines()
for line in lines:
if line.count("TTL"):
return True
return False
def worker_task(q):
while True:
ip_address = q.get()
RESULT[ip_address] = ping(ip_address)
q.task_done()
def ping_sweep(subnet):
q = queue.Queue()
for i in range(255):
worker = threading.Thread(target=worker_task,args=(q,),daemon=True)
worker.start()
for i in range(1,255):
q.put(subnet.format(i))
q.join()
print("sweep complete")
for ip in RESULT:
if RESULT[ip]:
print(ip,"up")
def tk_ping_sweep():
RESULT = {}
scan_address = entry.get()
if len(scan_address.split("."))==4:
subnet = ".".join(scan_address.split(".")[:-1])+".{}"
ping_sweep(subnet)
else:
print("invalid address")
RESULT = {}
window = tk.Tk()
label = tk.Label(window,text="Enter ip Address")
label.pack()
entry = tk.Entry(window)
entry.pack()
button = tk.Button(window,text="Sweep",command=tk_ping_sweep)
button.pack()
window.mainloop()
# if len((scan_address.split("."))==4):
# subnet = ".".join(scan_address.split(".")[:-1])+"."