In Python 3.3+ (or with this backport for 2.6 and 2.7), you can simply use ipaddress
:
import ipaddress
addr = str(ipaddress.ip_address(167772160))
assert addr == '10.0.0.0'
Alternatively, you can manually pack the value
import socket,struct
packed_value = struct.pack('!I', 167772160)
addr = socket.inet_ntoa(packed_value)
assert addr == '10.0.0.0'
You might also be interested in inet_pton
.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…