Created
August 25, 2014 06:50
-
-
Save rains31/686c6f195985f08e4809 to your computer and use it in GitHub Desktop.
ip地址和数字形式互转
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
| #IP地址之间的转换 | |
| import socket | |
| import struct | |
| def ip2long (ip): | |
| return struct.unpack("!I", socket.inet_aton(ip))[0] | |
| def long2ip (lint): | |
| return socket.inet_ntoa(struct.pack("!I", lint)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment