-
Notifications
You must be signed in to change notification settings - Fork 28
/
Copy pathmain.py
57 lines (45 loc) · 1.74 KB
/
main.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
# -*- coding: utf-8 -*-
import time
from datetime import datetime
import schedule
from hmpa import tshark
from config import config
from hmpa import serverchan
from hmpa import email
def brief_report(devices):
all_devices = devices['found_devices']
title = "{time} 一共发现了 {sum} 台设备".format(time=devices['time'],
sum=len(all_devices))
content = 'Known Devices: \n'
for dev in all_devices:
if dev['mac'] in list(config.known_devices.keys()):
content += '- {name} \n'.format(name=config.known_devices[dev['mac']])
content += '\n\nAll Devices: \n'
for dev in all_devices:
content += '- {mac} {rssi} {company} \n'.format(mac=dev['mac'],
rssi=int(dev['rssi']),
company=dev['company'])
return title, content
def job():
adapter = config.adapter
devices = tshark.scan(adapter, 60)
title, content = brief_report(devices)
print(content)
if config.use_email:
try:
print('send email notification')
mail = email.Email(config.email['user'], config.email['password'], config.email['host'], config.email['port'])
mail.send(config.email['to_user'], title, content.split('\n'))
except Exception as err:
print(err)
if config.use_wechat:
try:
print('send wechat notification')
serverchan.push(config.serverchan['sckey'], title, content=content)
except Exception as err:
print(err)
if __name__ == '__main__':
schedule.every(1).minutes.do(job)
while True:
schedule.run_pending()
time.sleep(1)