How can I find local IP addresses (i.e. 192.168.x.x or 10.0.x.x) in Python platform independently and using only the standard library?
Type "netstat -bn" and press "Enter" to get the list of IP addresses along with the processes that initiated the connections. The protocol, IP and status are displayed under each program.
I just found this but it seems a bit hackish, however they say tried it on *nix and I did on windows and it worked.
import socket s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM) s.connect(("8.8.8.8", 80)) print(s.getsockname()[0]) s.close()
This assumes you have an internet access, and that there is no local proxy.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With