Created
May 30, 2018 06:42
-
-
Save pbcquoc/0592b43d489e7b81ff9546e9651a0de9 to your computer and use it in GitHub Desktop.
python convert string to ipv4 in the correct way.
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, 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