此函数实现将数值型的IP地址转换成字串模式的地址(如xxx.xxx.xxx.xxx)
简单实现:
#!/usr/bin/env python
def intIPTostrIP(sourceIP):
sourceIP1 = (sourceIP>>24) & 0xFF
sourceIP2 = (sourceIP>>16) & 0xFF
sourceIP3 = (sourceIP>>8) & 0xFF
sourceIP4 = sourceIP & 0xFF
deststrIP = str(sourceIP1) + '.'
deststrIP += str(sourceIP2) + '.'
deststrIP += str(sourceIP3) + '.'
deststrIP += str(sourceIP4)
return deststrIP
if __name__ == '__main__':
while True:
strIP = intIPTostrIP(int(input('Enter your ip(0~4294967295):')))
print(strIP)