Skip to content

Instantly share code, notes, and snippets.

@omorandi
Created September 23, 2011 16:30
Show Gist options
  • Save omorandi/1237809 to your computer and use it in GitHub Desktop.
Save omorandi/1237809 to your computer and use it in GitHub Desktop.
ip_addr = "localhost"
s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
try:
s.connect(("gmail.com",80))
ip_addr = s.getsockname()[0]
except socket.error, msg:
s.close()
s = None
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment