You can use the socket module functions, for instance:
import socket
ip_string = '192.168.1.1'
print(socket.inet_aton(ip_string))
print(socket.inet_ntoa(socket.inet_aton(ip_string)))
print(socket.inet_pton(socket.AF_INET, '192.168.1.1'))
print(socket.inet_ntop(
socket.AF_INET, socket.inet_pton(socket.AF_INET, '192.168.1.1')))
packed_ip = b'\xd4\xfbuW'
print(socket.inet_ntoa(b'\xd4\xfbuW'))
Output
b'\xc0\xa8\x01\x01'
192.168.1.1
b'\xc0\xa8\x01\x01'
192.168.1.1
212.251.117.87
As you can see, 192.168.1.1 would correspond to \xC0\xA8\x01\x01 and b'\xd4\xfbuW' would be 212.251.117.87