Python 将IP转换为int

import socket
import struct

if __name__ == '__main__':
    ip = '127.0.0.1'
    int_ip = struct.unpack('!I', socket.inet_aton(ip))[0]
    print(int_ip)
    str_ip = socket.inet_ntoa(struct.pack('!I', int_ip))
    print(str_ip)

 

posted @ 2017-08-14 15:24  stone_wl  阅读(2302)  评论(0编辑  收藏  举报