-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathshowip.py
More file actions
40 lines (34 loc) · 909 Bytes
/
showip.py
File metadata and controls
40 lines (34 loc) · 909 Bytes
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
#!/usr/bin/python3
import socket
from tkinter import *
LOCALHOST = '127.0.0.1'
def getip():
s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
try:
# doesn't even have to be reachable
s.connect(('8.8.8.8', 80))
IP = str(s.getsockname()[0])
except Exception:
IP = LOCALHOST
finally:
s.close()
return IP
def isLinkUp():
if getip() == LOCALHOST:
return False
else:
return True
def update():
localIP.config(text=getip())
rootWindow.title(getip())
rootWindow.after(30000, update)
def main():
rootWindow = Tk()
rootWindow.title(getip())
localIP = Label(rootWindow, font = ('fixed', 20),)
localIP.grid(sticky = N, row = 2, column = 1, padx = 5, pady = (20,20))
localIP.config(text=getip())
rootWindow.after(30000, update)
rootWindow.mainloop()
if __name__ == '__main__':
main()