Skip to content

Instantly share code, notes, and snippets.

@sbliven sbliven/show_ip.py
Created Dec 5, 2017

Embed
What would you like to do?
Script to show current IP address on SenseHat
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
You can’t perform that action at this time.