Skip to content

Instantly share code, notes, and snippets.

@etaf
Created July 11, 2019 06:13
Show Gist options
  • Save etaf/4376072540ce69266f01b0ff9dd0c968 to your computer and use it in GitHub Desktop.
Save etaf/4376072540ce69266f01b0ff9dd0c968 to your computer and use it in GitHub Desktop.
python get host ip
import socket
def get_host_ip():
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