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)