I want to get my local IP address and also the subnet mask of the network with a python code. I tried this code for getting the IP address:
import socket
print socket.gethostbyname(socket.gethostname())
But I got this IP > 169.254.236.99, which is not my local IP address.
So maybe you can help me to do it? Thanks.
Edit: I found nice solution for the IP address that works on both Linux and Windows
import socket
s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
s.connect(("8.8.8.8", 80))
print(s.getsockname()[0])
So if you can help me with the subnet mask it will be pretty helpful :)