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

  • SEARCH
  • Home
  • 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 6369567
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T00:49:19+00:00 2026-05-25T00:49:19+00:00

I have this string IP 1.2.3.4 is currently trusted in the white list, but

  • 0

I have this string “IP 1.2.3.4 is currently trusted in the white list, but it is now using a new trusted certificate.” in a log file. What I need to do is look for this message and extract the IP address (1.2.3.4) from the log file.

import os
import shutil
import optparse
import sys

def main():
    file = open("messages", "r")
    log_data = file.read()
    file.close()

    search_str = "is currently trusted in the white list, but it is now using a new trusted certificate."

    index = log_data.find(search_str)
    print index

    return

if __name__ == '__main__':
    main()

How do I extract the IP address? Your response is appreciated.

  • 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-25T00:49:20+00:00Added an answer on May 25, 2026 at 12:49 am

    Use regular expressions.

    Code like this:

    import re
    
    compiled = re.compile(r"""
        .*?                                # Leading junk
        (?P<ipaddress>\d+\.\d+\.\d+\.\d+)  # IP address
        .*?                                # Trailing junk
        """, re.VERBOSE)
    str = "IP 1.2.3.4 is currently trusted in the white list, but it is now using a new trusted certificate."
    m = compiled.match(str)
    print m.group("ipaddress")
    

    And you get this:

    >>> import re
    >>> 
    >>> compiled = re.compile(r"""
    ...     .*?                                # Leading junk
    ...     (?P<ipaddress>\d+\.\d+\.\d+\.\d+)  # IP address
    ...     .*?                                # Trailing junk
    ...     """, re.VERBOSE)
    >>> str = "IP 1.2.3.4 is currently trusted in the white list, but it is now using a new trusted certificate."
    >>> m = compiled.match(str)
    >>> print m.group("ipaddress")
    1.2.3.4
    

    Also, I learned there there is a dictionary of matches, groupdict():

    >>>> str = "Peer 10.11.6.224 is currently trusted in the white list, but it is now using a new trusted certificate. Consider removing its likely outdated white list entry."
    >>>> m = compiled.match(str)
    >>>> print m.groupdict()
    {'ipaddress': '10.11.6.224'}
    

    Later: fixed that. The initial ‘.*’ was eating your first character match. Changed it to be non-greedy. For consistency (but not necessity), I changed the trailing match, too.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have this currently. ClickableSpan span = new ClickableSpan(...){...}; String text = I am
Currently I have this: [SomeCustomAttribute] public string Name { get; set; } However, I
currently, this is the preg_replace string that I have. $mtg_post['post_content'] = preg_replace([^\\x20-\\x7e], ,$ability); This
I have this string: 123-456-7 I need to get this string: 1234567 How I
I have this string stored in a variable: IN=bla@some.com;john@home.com Now I would like to
I'm currently serializing objects like this: public static string ObjToJson(List<MyObject> TheObjects){ JavascriptSerializer TheSerializer =
Currently I have this program: namespace EmptySiteCollectionRecycleBin { class Program { static void Main(string[]
I have a string (currently defined in my .h file) that I'd like to
I'm currently creating a Login form and have this code: string connectionString = ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString;
I currently have this file_put_contents($tmpfile, $attachments[0]['body']); $objPHPExcel = PHPExcel_IOFactory::load($tmpfile); The file I am reading

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.