话不多说,直接代码
ip_addr='192.168.2.10' # transfer ip to int def ip2long(ip): ip_list=ip.split('.') result=0 for i in range(4): #0,1,2,3 result=result+int(ip_list[i])*256**(3-i) return result long=3232236042 # transfer int to ip def long2ip(long): floor_list=[] yushu=long for i in reversed(range(4)): #3,2,1,0 res=divmod(yushu,256**i) floor_list.append(str(res[0])) yushu=res[1] return '.'.join(floor_list) a=long2ip(long) print(a)
no copyright !! 个人原创博客欢迎转载,可以不保留出处。