From owner-freebsd-questions@freebsd.org Sat Dec 8 02:38:52 2018 Return-Path: Delivered-To: freebsd-questions@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id 8B568132B920 for ; Sat, 8 Dec 2018 02:38:52 +0000 (UTC) (envelope-from freebsd@edvax.de) Received: from mout.kundenserver.de (mout.kundenserver.de [212.227.17.24]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (Client CN "mout.kundenserver.de", Issuer "TeleSec ServerPass DE-2" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id AFEA485DA6 for ; Sat, 8 Dec 2018 02:38:51 +0000 (UTC) (envelope-from freebsd@edvax.de) Received: from r56.edvax.de ([92.193.252.129]) by mrelayeu.kundenserver.de (mreue108 [212.227.15.183]) with ESMTPA (Nemesis) id 1MTREY-1gumMB2O8i-00Tp2m; Sat, 08 Dec 2018 03:38:43 +0100 Date: Sat, 8 Dec 2018 03:38:43 +0100 From: Polytropon To: Ernie Luzar Cc: freebsd-questions@freebsd.org Subject: Re: sh code to determine if host is on lan Message-Id: <20181208033843.19288a5e.freebsd@edvax.de> In-Reply-To: <5C0AEF17.7070100@gmail.com> References: <5C099F41.2020407@gmail.com> <5C09AB7B.4010001@gmail.com> <20181207011905.af7d5c29.freebsd@edvax.de> <5C09C491.1060803@gmail.com> <20181207195645.GA64030@geeks.org> <5C0AEF17.7070100@gmail.com> Reply-To: Polytropon Organization: EDVAX X-Mailer: Sylpheed 3.1.1 (GTK+ 2.24.5; i386-portbld-freebsd8.2) Mime-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit X-Provags-ID: V03:K1:GF/LHvl/OPMFt7dVnoVLm0up4E4UMs9pTHG2EExgaooIN9Zp345 hoaoIEKlx5alwo6YXR+PNMlcDc9Jg+M/FeefuP6L6I63tv0KlNri0UODHLpMdqmh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sd@edvax.de]; TO_DN_SOME(0.00)[]; MV_CASE(0.50)[]; HAS_ORG_HEADER(0.00)[]; MX_GOOD(-0.01)[cached: mx01.schlund.de]; RCPT_COUNT_TWO(0.00)[2]; FREEMAIL_TO(0.00)[gmail.com]; RECEIVED_SPAMHAUS_PBL(0.00)[129.252.193.92.zen.spamhaus.org : 127.0.0.10]; R_DKIM_NA(0.00)[]; RCVD_TLS_LAST(0.00)[]; ASN(0.00)[asn:8560, ipnet:212.227.0.0/16, country:DE]; IP_SCORE(-0.14)[ipnet: 212.227.0.0/16(-0.61), asn: 8560(-0.07), country: DE(-0.01)]; FROM_EQ_ENVFROM(0.00)[]; ARC_NA(0.00)[]; NEURAL_HAM_MEDIUM(-0.88)[-0.885,0]; REPLYTO_EQ_FROM(0.00)[]; FROM_HAS_DN(0.00)[]; NEURAL_SPAM_SHORT(0.02)[0.020,0]; NEURAL_HAM_LONG(-1.00)[-0.998,0]; MIME_GOOD(-0.10)[text/plain]; DMARC_NA(0.00)[edvax.de]; AUTH_NA(1.00)[]; TO_MATCH_ENVRCPT_SOME(0.00)[]; MID_CONTAINS_FROM(1.00)[]; RCVD_IN_DNSWL_NONE(0.00)[24.17.227.212.list.dnswl.org : 127.0.5.0]; R_SPF_NA(0.00)[]; RCVD_COUNT_TWO(0.00)[2] X-Rspamd-Server: mx1.freebsd.org X-BeenThere: freebsd-questions@freebsd.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: User questions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sat, 08 Dec 2018 02:38:52 -0000 On Fri, 07 Dec 2018 17:07:19 -0500, Ernie Luzar wrote: > Doug McIntyre wrote: > > On Thu, Dec 06, 2018 at 07:53:37PM -0500, Ernie Luzar wrote: > >> Polytropon wrote: > >>> elOn Thu, 06 Dec 2018 16:06:35 -0700, JD wrote: > >>>> On 12/06/2018 03:14 PM, Ernie Luzar wrote: > >>>>> Hello list > >>>>> > >>>>> Know that "route -n get default" will give me the nic name of the > >>>>> interface connected upstream. That "ifconfig nic" will give me the ip > >>>>> address. That if that ip address is one of these ranges > >>>>> 192.168/16 or 172.16/12 or 10/8 then the host is on a lan. > > > > Hmm, I thought my host here was on a LAN.. > > > > vmx0: flags=8843 metric 0 mtu 1500 > > inet 216.250.176.100 netmask 0xffffffe0 broadcast 216.250.176.127 > > inet6 2001:4980:2:dad::100 prefixlen 64 > > > > And this one too.. > > bce0: flags=8843 metric 0 mtu 1500 > > inet6 2001:4980:0:1000:21e:c9ff:feb5:663a prefixlen 64 autoconf > > inet6 2001:4980:0:ffff:21e:c9ff:feb5:663a prefixlen 64 autoconf > > > > Are you sure your definition of "LAN" is the correct term? > > > > What is it you are trying to determine? > > > > > > > Like most ISPs my ISP doesn't provide ipv6 service. So not interested in > it until it goes public nationwide. > > Your 216.250.176.100 ipv4 address is public routeable. Looks like this > machine is running vm and the freebsd os is configured as the gateway to > the public internet. If it has a LAN behind it using ipv4 addresses, > then this gateway is also running a firewall with NAT so the LAN nodes > can reach the public internet. > > I'm playing with 12.0-RC3 and vnet jails. Vnet jails come in two flavors > based on the hosts network topography. The host is either the gateway or > its a node on the lan. Lans use these reserved non-routeable ipv4 > address ranges for network communication. If the host's default ip > address is in the range covered by one of theses 192.168/16 or 172.16/12 > or 10/8 ranges then the host is a node on a lan. That is what I am > trying to determine in a sh script. I know that I can drill down through > a few standard commands to capture the hosts external ipv4 address easy > enough. But comparing it to the different ranges becomes a painful > coding task. So I understood your intention correctly: "Public or private IP?" is the question you've been trying to answer. > I think I just figured out the simple method I was looking for. Just > issue the whois command using the captured hosts external ipv4 address > and interrogate the reply for "Private Use". That is an interesting method! % whois 192.168.45.67 | grep "NetName:" NetName: PRIVATE-ADDRESS-CBLK-RFC1918-IANA-RESERVED % whois 172.16.50.10 | grep "NetName:" NetName: PRIVATE-ADDRESS-BBLK-RFC1918-IANA-RESERVED % whois 10.232.3.64 | grep "NetName:" NetName: PRIVATE-ADDRESS-ABLK-RFC1918-IANA-RESERVED The surrounding grepping, cutting, and $? magic is trivial. :-) -- Polytropon Magdeburg, Germany Happy FreeBSD user since 4.0 Andra moi ennepe, Mousa, ...