ip、数字的互转
ip、数字互转
# ip ==> 数字
>>> ip2num = lambda x:sum([256**j*int(i) for j,i in enumerate(x.split('.')[::-1])])
>>> ip2num('192.168.0.1')
3232235521
# 数字 ==> ip # 数字范围[0, 255^4]
>>> num2ip = lambda x: '.'.join([str(x/(256**i)%256) for i in range(3,-1,-1)])
>>> num2ip(3232235521)
'192.168.0.1'
来源:PY学习网:原文地址:https://www.py.cn/article.html