RASCSI/python/oled/src/pi_cmds.py
Benjamin Zeiss 089dc302e5
restructuring towards python client library #455 (#613)
* python client library clean branch for PR. #455

* removed superfluous file. #455

* removed one more superfluous file. #455

* README.md, .pylintrc and pylint based fixes. #455

* updated wrt. to the review comments. #455

* removed pylint documentation duplication. #455
2022-01-21 15:08:29 -08:00

22 lines
570 B
Python

"""
Module with methods that interact with the Pi's Linux system
"""
def get_ip_and_host():
"""
Use a mock socket connection to identify the Pi's hostname and IP address
"""
from socket import socket, gethostname, AF_INET, SOCK_DGRAM
host = gethostname()
sock = socket(AF_INET, SOCK_DGRAM)
try:
# mock ip address; doesn't have to be reachable
sock.connect(('10.255.255.255', 1))
ip_addr = sock.getsockname()[0]
except Exception:
ip_addr = False
finally:
sock.close()
return ip_addr, host