-
Notifications
You must be signed in to change notification settings - Fork 0
/
wifiscout.py
110 lines (81 loc) · 2.92 KB
/
wifiscout.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
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
import requests # to make HTTP requests
import json # library for handling JSON data
import time # time library
from boltiot import Bolt # importing Bolt from boltiot module
import conf # config file
import scapy.all as sc # import scapy library
try:
file = open('wifiscout-header.txt', 'r')
print (' ')
print (file.read())
file.close()
except IOError:
print ('\nBanner File not found!')
mybolt = Bolt(conf.bolt_api_key, conf.device_id)
iprange = input("Enter your Wireless network IP range :\n")
prevcount = 0
status = ""
while True :
currentcount = 0
# Function to Scan the IP
def scan(ip):
arp_request = sc.ARP(pdst = ip)
broadcast = sc.Ether(dst = "ff:ff:ff:ff:ff:ff")
x = broadcast/arp_request
answered_list = sc.srp(x, timeout=1, verbose=False)[0]
targets_list = []
for element in answered_list:
targets_dict = {"ip":element[1].psrc, "mac":element[1].hwsrc}
targets_list.append(targets_dict)
return targets_list
# Function to Print the Output Result
def result(results_list):
print("\nConnected Devices :")
print("\n-------------------------------------")
print("IP\t\tMAC Address\n-------------------------------------")
for target in results_list:
print(target["ip"] + "\t" + target["mac"])
global currentcount
currentcount = len(results_list)
print("\nNo. of active Device(s) in your Wifi : ", currentcount, "\n")
global prevcount
global status
if currentcount > prevcount :
diff = currentcount - prevcount
status = str(diff) + " new Device(s) were added in last 60 seconds\n"
print(status)
elif currentcount < prevcount :
diff = prevcount - currentcount
status = str(diff) + " new Device(s) were removed in last 60 seconds\n"
print(status)
else :
status = "No new Device(s) were added or removed in last 60 seconds\n"
print(status)
for i in range(0,currentcount):
mybolt.digitalWrite('0', 'HIGH')
time.sleep(0.05)
mybolt.digitalWrite('0', 'LOW')
prevcount = currentcount
scan_target = iprange
scan_result = scan(scan_target)
result(scan_result)
# Function to send output to Telegram
def telegram_message(message):
url = "https://api.telegram.org/" + conf.telegram_bot_id + "/sendMessage"
data = {"chat_id": conf.telegram_chat_id, "text": message}
try:
response = requests.request("POST", url, params=data)
#print("\nThis is the Telegram URL : ")
#print(url)
#print("\nThis is the Telegram response : ")
#print(response.text)
telegram_data = json.loads(response.text)
return telegram_data["ok"]
except Exception as e:
print("\nAn error occurred in sending the alert message via Telegram")
print(e)
return False
message = "Connected Devices :\n\n" + str(scan_result) + "\n\nNo. of active Devices in your Wifi : " + str(currentcount) + "\n\n" + status
telegram_status = telegram_message(message)
print("This is the Telegram status : ", telegram_status, "\n")
time.sleep(60)