Skip to content

Instantly share code, notes, and snippets.

@foolishflyfox
Created March 23, 2019 05:46
Show Gist options
  • Save foolishflyfox/7a62c3dedfabe1acb27278bd3f7c2571 to your computer and use it in GitHub Desktop.
Save foolishflyfox/7a62c3dedfabe1acb27278bd3f7c2571 to your computer and use it in GitHub Desktop.
Get local address with python
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