Created
March 23, 2019 05:46
-
-
Save foolishflyfox/7a62c3dedfabe1acb27278bd3f7c2571 to your computer and use it in GitHub Desktop.
Get local address with python
This file contains hidden or 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 getip(): | |
try: | |
_s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM) | |
_s.connect(('8.8.8.8', 80)) | |
ip = _s.getsockname()[0] | |
finally: | |
_s.close() | |
return ip | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment