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.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…