编程语言
首页 > 编程语言> > 利用python将ip转换为10进制

利用python将ip转换为10进制

作者:互联网

def int2ip(num):
data = []
for i in range(4):
num ,extra = divmod(num, 256)
data.insert(0, str(extra))
return ".".join(data)
def ip2int(astr):
ipnum = astr.split(".")
num = 0
for i in range(4):
num += int(ipnum[i]) * 256 ** (3-i)
return num

if name == "main":
print (int2ip(3232235786))
print(ip2int("192.168.1.10"))

标签:ipnum,10,int2ip,extra,python,ip,num,256,data
来源: https://www.cnblogs.com/doqingTeenager/p/14283636.html