forked from philippechataignon/smrt
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtp_analyse.py
executable file
·48 lines (38 loc) · 1.22 KB
/
tp_analyse.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
#!/usr/bin/env python
################################################################################################
# Listen to bidirectional network communication (to and from TP-Link switches / easy switch tool
# Analyze the network communications
import socket, time, random, argparse, logging
from protocol import Protocol
from network import Network
def show_packet(payload):
print(payload)
data = Protocol.decode(payload)
print("TEST: " + data.hex(" "))
try:
print(Protocol.analyze(data)[1])
except AssertionError:
return
except KeyError:
return
def main():
# Handle command-line parameters
parser = argparse.ArgumentParser()
parser.add_argument('--interface', '-i')
args = parser.parse_args()
# Instantiate network driver
net = None
try:
net = Network(args.interface, "fe:ff:ff:ff:ff:ff")
except InterfaceProblem as e:
print("Error:", e)
while True:
data = net.receive_socket(net.rs)
if data:
show_packet(data)
data = net.receive_socket(net.ss)
if data:
show_packet(data)
time.sleep(0.1)
if __name__ == '__main__':
main()