title: Python parse ip regex
body: <p>I want to be able to parse something like "10.[3-25].0.X" into the actual list of ip addresses described by this rule, so for the above example rule the list would be [10.3.0.0, 10.3.0.1....10.25.0.255]. What's the best way to do it?
  So far the only thing I was able to come out with is the following awful-looking function:</p>
  
  <pre><code>wc = ''.join(wc.split()).upper()
  wc = re.sub(r'(?&lt;![\[-])(\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
  </code></pre>
  
  <p>Any improvement ideas would be greatly appreciated.</p>