话不多说,直接代码

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)

 

相关文章:

  • 2022-12-23
  • 2022-12-23
  • 2021-07-31
  • 2022-12-23
  • 2021-06-25
  • 2021-12-13
  • 2021-12-02
  • 2022-02-13
猜你喜欢
  • 2021-07-31
  • 2021-12-03
  • 2021-10-15
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-06-26
相关资源
相似解决方案