5

Does anyone have a simple way to convert IPv6 addresses to dotted decimal notation?

I am currently using a pretty ugly python script which:

  1. Converts the IPv6 address to exploded form
  2. Splits every 2 hex characters and converts those to decimal
  3. Joins decimal numbers together with "." and returns the string

The use case for this is for SNMP lookups which as far as I know require dotted decimal notation. Is anyone aware of a simple/pretty solution to this problem?

Input:
 2607:f8b0:400a:801::200e
Output:
 38.7.248.176.64.10.8.1.0.0.0.0.0.0.32.14
1
  • That would be how you do it. If you are asking for a product, resource, or programming solution to do this for you, that is off-topic here. Commented Jan 16, 2016 at 0:08

2 Answers 2

2

Python 3 is your friend:

import sys
import ipaddress

ip6 = ipaddress.ip_address(sys.argv[1]).exploded.replace (':','')

".".join([str(int(ip6[index:index+2], 16)) for index in range(0,len(ip6), 2)])
1
  • If I might suggest: ".".join([str(x) for x in ipaddress.ip_address(sys.argv[1]).packed]) Commented Sep 13, 2017 at 12:19
4

Take a look at https://pypi.python.org/pypi/IPy/. It allows you to automatically parse the (many formats of the) IPv6 address and return various formats you can use to format.

0

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.