「10.[3-25].0.X」のようなものを、このルールで記述された IP アドレスの実際のリストに解析できるようにしたいので、上記の例のルールの場合、リストは [10.3.0.0, 10.3] になります。 .0.1....10.25.0.255]。それを行う最良の方法は何ですか?これまでのところ、私が思いついたのは、次の見栄えの悪い関数だけです。
wc = ''.join(wc.split()).upper()
wc = re.sub(r'(?<![\[-])(\d+)(?![\]-])', r'[\1-\1]', wc)
wc = re.sub(r'X', r'[0-255]', wc).split('.')
ips = []
for i in range(int(re.findall(r'(\d+)-(\d+)', wc[0])[0][0]), int(re.findall(r'(\d+)-(\d+)', wc[0])[0][1]) + 1):
for j in range(int(re.findall(r'(\d+)-(\d+)', wc[1])[0][0]), int(re.findall(r'(\d+)-(\d+)', wc[1])[0][1]) + 1):
for k in range(int(re.findall(r'(\d+)-(\d+)', wc[2])[0][0]), int(re.findall(r'(\d+)-(\d+)', wc[2])[0][1]) + 1):
for p in range(int(re.findall(r'(\d+)-(\d+)', wc[3])[0][0]), int(re.findall(r'(\d+)-(\d+)', wc[3])[0][1]) + 1):
ips.append(str(i) + '.' + str(j) + '.' + str(k) + '.' + str(p))
return ips
改善のアイデアをいただければ幸いです。