Skip to content

Instantly share code, notes, and snippets.

@pbcquoc
Created May 30, 2018 06:42
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save pbcquoc/0592b43d489e7b81ff9546e9651a0de9 to your computer and use it in GitHub Desktop.
Save pbcquoc/0592b43d489e7b81ff9546e9651a0de9 to your computer and use it in GitHub Desktop.
python convert string to ipv4 in the correct way.
import socket, struct
def str2ip(ip):
"Convert dotted IPv4 address to integer."
packedIP = socket.inet_aton(ip)
return struct.unpack("!i", packedIP)[0]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment