I'm trying to figure out the best way to perform a host-bit to host-bit NAT translation in python. For example:
from ipaddress import IPv4Address
# We have some IPs in the 192.168.0.0/26 and 172.31.0.0/27 networks
IPv4Address('192.168.0.15') # /26 net prefix length
IPv4Address('172.31.0.26') # /27 net prefix length
# We need to translate them to their new respective NAT IPs
# in the 10.15.0.0/26, 10.15.0.0/27 networks,
# but matching original host bits (.15, .26)
IPv4Address('10.15.0.15') # /26 net prefix length
IPv4Address('10.15.0.26') # /27 net prefix length
In my use case, let's assume that the original network and NAT network prefix lengths will always match each other (whether that is /16,/24 /28, etc). How would I programmatically calculate the host bits of some original IP and map it to its corresponding NAT IP as a IPv4Address object?
Please let me know if any other info is needed. Thanks!