Skip to content

Instantly share code, notes, and snippets.

@sbliven sbliven/
Created Dec 5, 2017

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(('', 53))
ip = s.getsockname()[0]
return 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.