将ipv4地址转换为不同格式(python程序)
import socket
from binascii import hexlify
for ip_addr in ['127.0.0.1']:
packed_ip_addr=socket.inet_aton(ip_addr)
unpacked_ip_addr=socket.inet_ntoa(packed_ip_addr)
print "IP address: %s=> Packed: %s,Unpacked:%s"\
%(ip_addr,hexlify(packed_ip_addr),unpacked_ip_addr)