How do I increment the IP address in python when we have start_ip in 4 octets
format and the step also in 4 octet format.
Let's suppose I start with an IP address of 225.1.1.1
, and the step as 0.0.0.1
When I say next_ip = start_ip + step, it should actually evaluate the expand produce the result.
I know that the ipaddr
module does this with just an addition, but that does not seem to work when the step is also given in the ipv4 format.
Any known steps to do this:
import ipaddr
a = ipaddr.ipaddress('225.1.1.1')
b = a +1
This actually returns the desired result. but when increment like this:
b = a + 0.0.0.1 it does not seem to work.
Any known solutions for this?
this piece of code can add two 4 octets :
first = '192.168.0.4'
second = '0.0.0.1'
ipaddress.ip_address(first) + int(ipaddress.ip_address(second))
this will result in: IPv4Address('192.168.0.5')