regex - output expanded ip list from text in python -


i have text contains ip , subnet data. need output each ip within given range. input looks this:

10.14.21.23 0.0.0.0   20.54.0.0 0.0.127.255   30.76.21.0 0.0.0.255   40.24.21.135 0.0.0.0   

and output needs this:

10.14.21.23   20.54.0.1   20.54.0.2   20.54.0.3   20.54.0.4   ...    20.54.127.254   30.76.21.1   30.76.21.2   30.76.21.3   30.76.21.4   ...    30.76.21.254    40.24.21.135   

i have isolated ips with:

for line in file.readlines():     if re.findall(r'\d+\.\d+\.\d+\.\d+?', line):         tuples = re.findall(r'\d+\.\d+\.\d+\.\d+', line) 

this places ip , subnet tuples[0] , tuples[1]. best way handle data? how calculate each ip within given range?

thanks in advance.

you use ipcalc:

#!/usr/bin/python import ipcalc import sys  data in sys.argv[1:]:   open(data) data:     data in data:       data = data.split()       # convert subnet mask count       data[1] = ipcalc.ip(data[1]).bin().count('0')       data = ipcalc.network(*data)       data = list(data)       if len(data) == 1:         print data[0]       else:         data in data[1:-1]:           print data 

ref:


Comments

Popular posts from this blog

Android layout hidden on keyboard show -

google app engine - 403 Forbidden POST - Flask WTForms -

c - Why would PK11_GenerateRandom() return an error -8023? -