原文:http://blog.chinaunix.net/uid-21516619-id-1824975.html








































#
IP地址之间的转换
import socket
import struct
def ip2hex (ip):
return hex(struct.unpack( " !I " , socket.inet_aton(ip))[0])
def ip2long (ip):
return struct.unpack( " !I " , socket.inet_aton(ip))[0]
def long2ip (lint):
return socket.inet_ntoa(struct.pack( " !I " , lint))
import socket
import struct
def ip2hex (ip):
return hex(struct.unpack( " !I " , socket.inet_aton(ip))[0])
def ip2long (ip):
return struct.unpack( " !I " , socket.inet_aton(ip))[0]
def long2ip (lint):
return socket.inet_ntoa(struct.pack( " !I " , lint))