Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 4112222
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T22:10:03+00:00 2026-05-20T22:10:03+00:00

I have been writing a python script and I am having a problem with

  • 0

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.

Here’s the function:

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

heres the ouput when called:

None
<_sre.SRE_Match object at 0xb76964b8>
<_sre.SRE_Match object at 0xb7696db0>
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-20T22:10:04+00:00Added an answer on May 20, 2026 at 10:10 pm

    The re.search is returning a Match Object. This is an object which has a number of attributes which tell you about the match.

    To get the whole matched text use ip.group(0) or ip.group().

    Also re.search doesn’t throw an exception if there is no match, and instead returns None. So your code should look something like:

    ip = re.search(r"\b(?:[0-9]{1,3}\.){3}[0-9]{1,3}\b",line)
    
    if ip is None:
        ip = "none set"
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a C++/Obj-C background and I am just discovering Python (been writing it
For the last couple of months I have been writing an intranet site for
I understand object oriented programming, and have been writing OO programs for a long
I have been thinking of maybe writing a little tool that logs into SO
I've been writing PHP for about six years now and have got to a
I've been writing PHP web applications for some time, and have come across very
I have just been getting into low level programming (reading/writing to memory that sort
I have been writting a keyword search script based on this tutorial: http://www.hackosis.com/2007/11/06/howto-simple-search-engine-with-php-and-mysql/ Like
I'm writing an application in Python that is going to have a lot of
I am writing a python script that will be doing some processing on text

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.