-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathgraphical_netcfg.py
75 lines (60 loc) · 2.61 KB
/
graphical_netcfg.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
# for 3.x python:
import tkinter as tk
from tkinter.ttk import *
# # for 2.7 python:
# import Tkinter as tk
# from Tkinter import *
from subprocess import call, Popen, PIPE, STDOUT
class App():
def __init__(self):
self.root = tk.Tk()
self.root.title("devices networks")
self.labels = []
self.update_clock()
self.root.mainloop()
def update_clock(self):
i = 0
# This is the path of adt when intsalling android studio 1.2 on windows
adb_absolute_path = "C:\\Users\\ilan.MAXTECH\\AppData\\Local\\Android\\Sdk\\Platform-tools\\"
# destroy all old labels so that they can be garbage collected
# Clear the labels from last clock cycle
for label in self.labels:
label.grid_remove()
label.destroy()
# for 3.x python:
self.labels.clear();
## for 2.7 python:
#del self.labels[:]
# Get the list of connected devices
cmd = adb_absolute_path + "adb.exe devices"
proc = Popen(cmd, shell=True, stdout=PIPE, stderr=STDOUT)
device_list = proc.communicate()[0].decode().split("\r\n")
# remove unnecessary text in devices call
device_list.pop(0)
device_list.remove("")
device_list.remove("")
# retrieve maximum Device row to adjust the window dynamically to max rows
maxRowsColumn = 0
# print netcfg for each device
for device in device_list:
# get the netcfg for specific device
device_serial = device.split("\t")[0]
cmd = adb_absolute_path + "adb.exe -s " + device_serial + " shell netcfg"
proc = Popen(cmd, shell=True, stdout=PIPE, stderr=STDOUT)
netcfg_output = proc.communicate()[0].decode()
# add a new label to the screen
lb = Label(self.root, text=device_serial + "\n" +"interface status \t\t ip \t \t flag \t mac"+ "\n\n"+ netcfg_output)
lb.grid(row=1, column=i)
lbblank = Label(self.root, text="\t\n|\n|\n|\n|\n|\n|\n|\n|\n|\n|\n|\n|\n|\n|\n|\n|\n|\n|")
lbblank.grid(row=1, column=i + 1)
i += 2
self.labels.append(lb)
self.labels.append(lbblank)
# the // 50 is to get approximately the line avg length and not every char
# +5 is the static additional lines
var = netcfg_output.__len__() // 50 + 3
if var > maxRowsColumn:
maxRowsColumn = var
self.root.geometry(str(device_list.__len__() * 450) + "x" + str(maxRowsColumn * 25))
self.root.after(1000, self.update_clock)
app = App()