Created
December 5, 2017 17:42
-
-
Save sbliven/fbba43dfbc7d10bd2e7a319277c16a36 to your computer and use it in GitHub Desktop.
Script to show current IP address on SenseHat
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from sense_hat import SenseHat | |
import socket | |
def get_ip(): | |
# overridden by /etc/hosts, so doesn't work for us | |
#hosts_ips = [ip for ip in socket.gethostbyname_ex(socket.gethostname())[2] if not ip.startswith("127.")][:1] | |
# try to connect to google | |
s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM) | |
s.connect(('8.8.8.8', 53)) | |
ip = s.getsockname()[0] | |
s.close() | |
return ip | |
print("IP="+get_ip()) | |
sense = SenseHat() | |
sense.show_message("IP: %s" % get_ip()) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment