Search code examples
pythonipv4

How to access specific numbers of a ipv4 address?


I have many ipv4 addresses with the fourth octet obfuscated with a 3 character string like (###.###.###.xxx) and i need to define each number between the dots.
For example 22.123.567.cjj than w=22, x=123 and y=567.
Sometimes the first octet has 3 numbers or (how you can see) 2 and sometimes just 1.

Can anyone help me ?


Solution

  • You could use the split() function.

    >>> address = "127.0.10.15"
    >>> print(address.split('.'))
    ['127', '0', '10', '15']