ipv4转整数,整数转ipv4

ip2long = lambda x: sum([256 ** j * int(i) for j, i in enumerate(x.split('.')[::-1])])
long2ip = lambda x: '.'.join(['{:0>3d}'.format(x // (256 ** i) % 256) for i in range(3, -1, -1)])

print(ip2long('8.8.8.8')  # 输出 134744072
print(long2ip(134744072)) # 输出 008.008.008.008

 

posted @ 2022-03-10 22:34  xuecl  阅读(120)  评论(0编辑  收藏  举报