-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathip_address.py
More file actions
35 lines (27 loc) · 915 Bytes
/
ip_address.py
File metadata and controls
35 lines (27 loc) · 915 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
import socket
import time
import requests
from screen import Screen
class IpAddress(Screen):
def __init__(self, hat):
self.hat = hat
def up(self):
return "Diagnostics"
def down(self):
return "BinaryClock"
def getLocalIp(self):
return socket.gethostbyname(socket.getfqdn())
def printLocalIp(self):
self.hat.show_message(self.getLocalIp(), scroll_speed=0.1, text_colour=[100,0,0])
def getWan(self):
ret = requests.request('GET', 'http://myip.dnsomatic.com')
return ret.text
def printWan(self):
try:
self.hat.show_message(self.getWan(), scroll_speed=0.1, text_colour=[100,0,0])
except Exception as e:
self.hat.show_message("No IP", scroll_speed=0.1, text_colour=[100,0,0])
def run(self, going):
while going.isSet():
self.printWan()
time.sleep(2)