Created
July 9, 2017 10:40
-
-
Save MattWoodhead/541f23ecd9b464adf2b2e1598aa9261d to your computer and use it in GitHub Desktop.
OS agnostic method to find local IP address. Requires internet connection.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import socket | |
def ip_check(): | |
""" uses the cockets module to find the local IP address """ | |
s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM) | |
s.connect(("8.8.8.8", 80)) # Ping Google DNS server | |
ip_address = s.getsockname()[0] | |
s.close() | |
return ip_address | |
print(ip_check()) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment