From nobody Mon Apr 4 14:08:44 2022 X-Original-To: questions@mlmmj.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mlmmj.nyi.freebsd.org (Postfix) with ESMTP id 0223D1A9E289 for ; Mon, 4 Apr 2022 14:09:07 +0000 (UTC) (envelope-from soyeomul@doraji.xyz) Received: from yw-1204.doraji.xyz (yw-1204.doraji.xyz [185.17.255.72]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256 client-signature RSA-PSS (2048 bits) client-digest SHA256) (Client CN "yw-1204.doraji.xyz", Issuer "R3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4KXCLn5W5Wz4gFN for ; Mon, 4 Apr 2022 14:09:05 +0000 (UTC) (envelope-from soyeomul@doraji.xyz) Received: from mail-pj1-f71.google.com (mail-pj1-f71.google.com [209.85.216.71]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256 client-signature RSA-PSS (2048 bits) client-digest SHA256) (Client CN "smtp.gmail.com", Issuer "GTS CA 1D4" (verified OK)) by yw-1204.doraji.xyz (Postfix) with ESMTPS id 2C83890B for ; Mon, 4 Apr 2022 14:08:58 +0000 (UTC) DKIM-Filter: OpenDKIM Filter v2.11.0 yw-1204.doraji.xyz 2C83890B DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=doraji.xyz; s=yw-1204-doraji-xyz; t=1649081338; bh=XzN8VFxR1pysXi2rhY734ZsuHDDpAw/tfRjuaObhsSY=; h=From:To:Subject:References:Date:In-Reply-To:From; b=hdj63hL80vcBYtyDE9iTYmYSNQIQbtmh00hB7u48CNIAaQ5DRe5Hd+ncW0O+BQgS9 Ej9L4XSvv5lWyYCF/Kx1R+nCfFJ75BjrHjDAqbdPn1Fa3kFZEkpGB78isOv4HQvKDR okQcm/lTpQSrl8pJ9S18CCguR5jdEk5+ohr/zmvUbISPxVavFWubnmfzUWHoZaMnDe MRNdCCESVDUZOSecgUf9DQ6ie2wOyH0K7IobdjclaXqAnsfb7obHH18jjfy9aGKpZT ZfCpO6LM72RfNfvwbWlZvj2wpV9dAvpwz08H0mNKv8QrWSl25t1VXXgSq3XYKrpK0z 7nZH9mskHEMZA== Received: by mail-pj1-f71.google.com with SMTP id x3-20020a17090a6c0300b001cab7230b41so568008pjj.9 for ; Mon, 04 Apr 2022 07:08:58 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:subject:organization:references :mail-followup-to:date:in-reply-to:message-id:user-agent :mime-version:content-transfer-encoding; bh=XzN8VFxR1pysXi2rhY734ZsuHDDpAw/tfRjuaObhsSY=; b=tYak1hS9WiD9ni0XUxCmLdZlIErd40nEnMDpWydyQNo+bJ3tEsOBkIOoWkYLX+BQvF +w3Y3oyifLB2Y7KpOAcC3G47gvVCBPhVwl3DJy102yGWFq6zQgQSFWSq3+NHPUJ5eFsk hxYWBoOIREmNoJqFs6d6SYAjq9ScQDTirug4hC3XYUgVYJzcqS8Rao1S8PU5amWhmqKd 2zeCsUig/PiJIQQBjEnMkxRmsjR9O5nP9GC47dzddPNgwAyu56o43KkFf8Ik4Vy2twvs Kr5tUwlG1Jp5tf5UP9nHNfLDQQmekS4aABZx6/wMr8iZAAUanQOKmtU57KFTXawbGMWH 5hDA== X-Gm-Message-State: AOAM531JYEmf4/gJYyjhAbdHex/YNLXNOZh2muwJ5DGnoaDh2QtS/JpV /GYe5TJQ6hIHfy1fNjfGXRlRZaXpnJdNtZvflUEvcTLliU8u17ftY4sJZ9INrCN2jRyqeHKfAbs ZFSXGUbMUYb94VRvkCxbTaACa X-Received: by 2002:a17:90a:49c1:b0:1ca:c243:db77 with SMTP id l1-20020a17090a49c100b001cac243db77mr60324pjm.215.1649081336147; Mon, 04 Apr 2022 07:08:56 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyEdifCP/0DshB07cXi6H1uWhx5HNZa0JfbEW3vR1HcD0c+RNGI18P4p/re2rYQMcJPniNNnQ== X-Received: by 2002:a17:90a:49c1:b0:1ca:c243:db77 with SMTP id l1-20020a17090a49c100b001cac243db77mr60289pjm.215.1649081335714; Mon, 04 Apr 2022 07:08:55 -0700 (PDT) Received: from penguin ([2001:2d8:6d71:b22a:216:3eff:fe15:56c0]) by smtp.gmail.com with ESMTPSA id x38-20020a056a0018a600b004fafd05ac3fsm12974666pfh.37.2022.04.04.07.08.52 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 04 Apr 2022 07:08:55 -0700 (PDT) Received: by penguin (sSMTP sendmail emulation, from userid 1000); Mon, 04 Apr 2022 23:08:44 +0900 From: Byung-Hee HWANG To: questions@freebsd.org Subject: Re: extracting an IPv4 address from text? Organization: =?utf-8?B?6YeR6Zm1ICjsl7Dsm5DsnZgg66eI7J2MKQ==?= References: <25160.44484.392802.868667@jerusalem.litteratus.org> X-YW-Thanks-Thanks-Thanks: =?utf-8?B?KOuMgOyInCAxNTLrhYQpIOyynO2VmOywvQ==?= =?utf-8?B?7IOd7J2EIOuBneq5jOyngCDri6Qg7IK066as7Iuc66Ck64qUIOuniOydjC4u?= =?utf-8?B?Ll5eXjs=?= Mail-Followup-To: questions@freebsd.org Date: Mon, 04 Apr 2022 23:08:44 +0900 In-Reply-To: <25160.44484.392802.868667@jerusalem.litteratus.org> (Robert Huff's message of "Sat, 2 Apr 2022 16:10:44 -0400") Message-ID: <87ee2daqkz.fsf@penguin> User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/27.1 (aarch64-unknown-linux-gnu) List-Id: User questions List-Archive: https://lists.freebsd.org/archives/freebsd-questions List-Help: List-Post: List-Subscribe: List-Unsubscribe: Sender: owner-freebsd-questions@freebsd.org X-BeenThere: freebsd-questions@freebsd.org MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable X-Rspamd-Queue-Id: 4KXCLn5W5Wz4gFN X-Spamd-Bar: - Authentication-Results: mx1.freebsd.org; dkim=pass header.d=doraji.xyz header.s=yw-1204-doraji-xyz header.b=hdj63hL8; dmarc=none; spf=none (mx1.freebsd.org: domain of soyeomul@doraji.xyz has no SPF policy when checking 185.17.255.72) smtp.mailfrom=soyeomul@doraji.xyz X-Spamd-Result: default: False [-1.80 / 15.00]; RCVD_VIA_SMTP_AUTH(0.00)[]; ARC_NA(0.00)[]; R_DKIM_ALLOW(-0.20)[doraji.xyz:s=yw-1204-doraji-xyz]; NEURAL_HAM_MEDIUM(-1.00)[-0.998]; FROM_HAS_DN(0.00)[]; TO_MATCH_ENVRCPT_ALL(0.00)[]; NEURAL_HAM_LONG(-1.00)[-1.000]; MIME_GOOD(-0.10)[text/plain]; PREVIOUSLY_DELIVERED(0.00)[questions@freebsd.org]; TO_DN_NONE(0.00)[]; RCPT_COUNT_ONE(0.00)[1]; HAS_ORG_HEADER(0.00)[]; RCVD_COUNT_THREE(0.00)[4]; MID_RHS_NOT_FQDN(0.50)[]; DKIM_TRACE(0.00)[doraji.xyz:+]; NEURAL_HAM_SHORT(-1.00)[-1.000]; RCVD_IN_DNSWL_NONE(0.00)[209.85.216.71:received]; MLMMJ_DEST(0.00)[questions]; R_SPF_NA(0.00)[no SPF record]; DMARC_NA(0.00)[doraji.xyz]; FROM_EQ_ENVFROM(0.00)[]; MIME_TRACE(0.00)[0:+]; SUBJECT_ENDS_QUESTION(1.00)[]; ASN(0.00)[asn:31400, ipnet:185.17.255.0/24, country:DE]; RCVD_TLS_ALL(0.00)[] X-ThisMailContainsUnwantedMimeParts: N Dear Robert, Robert Huff 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) # 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_^))//