0

I need to create a reverse DNS entry for IPv4.

The ip address is 108.61.190.64

But the reverse DNS entry is = each octet in reverse order with the last octet dropped

i.e.

$ORIGIN 190.61.108.IN-ADDR.ARPA.

or

12.34.56.78 ->  78.56.34.12

Is there a Python tool for this task? [::-1] does a complete reverse and not just rearranging the octets.

P.S. I have the same reverse issue for IPv6 but no octet is to be dropped.

mine
  • 235
  • 2
  • 10

1 Answers1

1

I guess you can do something similar to this:

>>> ip = '12.34.56.78'
>>> reversed = '.'.join(ip.split('.')[::-1])
>>> reversed
'78.56.34.12'

And if you want to drop the last one:

>>> ip = '12.34.56.78'
>>> reversed = '.'.join(ip.split('.')[::-1][:-1])
>>> reversed
'78.56.34'
Georgi Dimitrov
  • 173
  • 3
  • 5