python IP地址转换
IP地址从点分十进制到整型转换:
[code]
import socket
import struct
print struct.unpack("!L",socket.inet_aton("192.168.1.1"))[0]
[/code]
IP地址从整型到点分十进制转换:
[code]
import socket
import struct
print socket.inet_ntoa(struct.pack("!L",integer)
[/code]
print struct.unpack("!L",socket.inet_aton("192.168.1.1"))[0]
[/code]
print socket.inet_ntoa(struct.pack("!L",integer)
[/code]
评论已关闭