Skip site navigation (1)Skip section navigation (2)
Date:      Mon, 04 Apr 2022 23:08:44 +0900
From:      Byung-Hee HWANG <soyeomul@doraji.xyz> 
To:        questions@freebsd.org
Subject:   Re: extracting an IPv4 address from text?
Message-ID:  <87ee2daqkz.fsf@penguin>
In-Reply-To: <25160.44484.392802.868667@jerusalem.litteratus.org> (Robert Huff's message of "Sat, 2 Apr 2022 16:10:44 -0400")
References:  <25160.44484.392802.868667@jerusalem.litteratus.org>

next in thread | previous in thread | raw e-mail | index | archive | help

Dear Robert,

Robert Huff <roberthuff@rcn.com> writes:

> Hello:
> 	Let's suppose I want to parse a line from auth.log and extract
> the IP address (if any) to stdout.
> 	(...thanks...)

#+BEGIN_SRC python
# -*- coding: utf-8 -*

import re

p = re.compile("\
[1-9]?[0-9]?[0-9]\.[0-9]?[0-9]?[0-9]\.[0-9]?[0-9]?[0-9]\.[0-9]?[0-9]?[0-9]")

FPATH = "auth.log" # you can edit here

f = open(FPATH, "r")
data = f.read()

f.close()

result = p.findall(data) # <class 'list'>

if __name__ == "__main__":
    print(result)
    print(len(result))
#+END_SRC

It is python3 script, thanks!

Sincerely, Byung-Hee

-- 
^고맙습니다 _白衣從軍_ 감사합니다_^))//



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?87ee2daqkz.fsf>