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 =3D 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 =3D "auth.log" # you can edit here

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

f.close()

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

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

It is python3 script, thanks!

Sincerely, Byung-Hee

--=20
^=EA=B3=A0=EB=A7=99=EC=8A=B5=EB=8B=88=EB=8B=A4 _=E7=99=BD=E8=A1=A3=E5=BE=9E=
=E8=BB=8D_ =EA=B0=90=EC=82=AC=ED=95=A9=EB=8B=88=EB=8B=A4_^))//



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