Regardless of platform, use standard library Please tell me how to find the local ip address (192.168.x.x or 10.0.x.x)
python ip-address network
The modules associated with the network are socket
socket.gethostbyname(hostname) translates hostname
to an IPv4 address (string).
socket.getfqdn(name) will receive name
and return it to the domain name.
(However, if name
is empty, interpret it as a local host)
import socket
socket.gethostbyname(socket.getfqdn())
If you write it like this
socket.getfqdn
returns the local domain name
gethostbyname
takes this domain name and returns the IPv4 address.
© 2024 OneMinuteCode. All rights reserved.