Getting the local IP address will return the primary IP address of the host machine.
Use socket.gethostbyname()
to get the local IP address
Use socket.gethostname()
to get the hostname of the host machine. Call socket.gethostbyname(hostname)
with hostname
as the hostname of the host machine to get the local IP address.
hostname = socket.gethostname()
local_ip = socket.gethostbyname(hostname)
print(local_ip)
Output
172.17.0.2
https://www.kite.com/python/answers/how-to-get-the-local-ip-address-in-python
Sem comentários:
Enviar um comentário