title: Python regex read /etc/resolv.conf and return ip address only, think its almost there,
body: <p>I have been writing a python script and I am having a problem with a certain function, its supposed to open the /etc/resolv.conf file, read it line by line and return only the ip addresses. Although it appears to be finding the ip address ,it's not telling me then only what part of memory there in any idea how to get it to tell me the matching string itself.</p>
  
  <p>Here's the function:</p>
  
  <pre><code>def get_resolv():
      nameservers=[]
      rconf = open("/etc/resolv.conf","r")
      line = rconf.readline()
      while line:
          try:
              ip = re.search(r"\b(?:[0-9]{1,3}\.){3}[0-9]{1,3}\b",line)
  
  
          except:
              ip = "none set"
          print ip
          nameservers.append(ip)
          line= rconf.readline()
  
      return nameservers
  </code></pre>
  
  <p>heres the ouput when called:</p>
  
  <pre><code>None
  &lt;_sre.SRE_Match object at 0xb76964b8&gt;
  &lt;_sre.SRE_Match object at 0xb7696db0&gt;
  </code></pre>