Fetching the IP address using MicroPython

Question:

Trying to use pybricks-micropython

Want to get the localhost name/IP address. Can do in CPython with this code… but doesn’t seem to be an equivalent I can find in MicroPython?

hostName = socket.gethostname()
hostIPA = socket.gethostbyname(hostName)

Searching on the net, but cannot seem to find anything I can use?

Asked By: user3069232

||

Answers:

Special Thanks to David Lechner who pointed me in the right direction and gave 95% of this answer.

os.popen('hostname -I'.read().strip().split(" "))

Gives you the IP4 address!

Answered By: user3069232
Categories: questions Tags: , ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.