-
Notifications
You must be signed in to change notification settings - Fork 1
/
ip_display.py
executable file
·68 lines (61 loc) · 2.07 KB
/
ip_display.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
#!/usr/bin/python3
#
# Dipslays the IP address, Host name and Gateway
import os
import socket
import time
from tkinter import *
host = "None"
ipaddr = "None"
gateway = "None"
update = 5000
#
def update_ip():
global frame
try:
gw = os.popen("ip -4 route show default").read().split()
s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
s.connect((gw[2], 0))
ipaddr = s.getsockname()[0]
gateway = gw[2]
host = socket.gethostname()
s.close()
except:
gateway = "None"
host = "None"
ipaddr = "None"
frame.config(text="Host name = "+host+"\nIp Address = "+ ipaddr + "\nGateway =" + gateway, anchor="c")
frame.after(update,update_ip)
def update_ip_nl():
global frame
gw = os.popen("ip -4 route show default").read().split()
s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
s.connect((gw[2], 0))
ipaddr = s.getsockname()[0]
gateway = gw[2]
host = socket.gethostname()
s.close()
frame.config(text="Host Name = "+host+"\nIp Address = "+ ipaddr + "\nGateway =" + gateway, anchor="c")
root = Tk ()
root.title("IP Adresses")
windowWidth = root.winfo_reqwidth()
windowHeight = root.winfo_reqheight()
# Gets both half the screen width/height and window width/height
positionRight = int(root.winfo_screenwidth()/2 - windowWidth/2)
positionDown = int(root.winfo_screenheight()/2 - windowHeight/2)
# Positions the window in the center of the page.
root.geometry("+{}+{}".format(positionRight, positionDown))
frame1 = Text(root, height=5, width=41,bg='#2f2f34')
frame = Label(root, font=('times', 20, 'bold'),bg='#2f2f34',fg='#cdcdd1')
frame.pack(fill=BOTH, expand=1)
frame1.pack()
logo = PhotoImage(file='/home/pi/CSU_Pi_Class/Keysight_Logo.PNG')
frame1.image_create("current",image=logo)
frame.config(text="Host name = "+host+"\nIp Address = "+ ipaddr + "\nGateway =" + gateway, anchor="c")
b=Button(root, text="Refresh", anchor=S, command=update_ip_nl)
b.pack()
#time.sleep(5)
# Main
frame.after(update,update_ip)
# Start main loop
root.mainloop( )