From owner-freebsd-questions@freebsd.org Fri Dec 7 00:53:41 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 E9F861323744 for ; Fri, 7 Dec 2018 00:53:40 +0000 (UTC) (envelope-from luzar722@gmail.com) Received: from mail-it1-x142.google.com (mail-it1-x142.google.com [IPv6:2607:f8b0:4864:20::142]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (Client CN "smtp.gmail.com", Issuer "Google Internet Authority G3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 391B56FB2B for ; Fri, 7 Dec 2018 00:53:40 +0000 (UTC) (envelope-from luzar722@gmail.com) Received: by mail-it1-x142.google.com with SMTP id g76so4502674itg.2 for ; Thu, 06 Dec 2018 16:53:40 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=message-id:date:from:user-agent:mime-version:to:cc:subject :references:in-reply-to:content-transfer-encoding; bh=PVqaB1SavaUPB1vasl4Nb3wwxUzBTfCxswU6AUGgUpw=; b=F1IFH1sW1HQrQ3fdyx3pCVoZhjPRyHuY7KMMcIxzwkso5TMkQlNDZu8XX5khPM6JNg bqU7rM5lMqaeR2nDgTACdBczzubzi8y9jj+I/Wp3/pHLI1EYpUL6U52MisWky2Jf+vO7 m5dg1CgHZckX5g+l38Y3aHguvXDt/TZqVM0nO9O8lPz9g3T3l0JpGHpkFQU4JSptXR3p 8o1G9EcF134F1kiL2lmajmckZ6iuS7cjsRxuyktG5uTJ3Is3M8RiDksr8YDSCs0vnnZJ tdRDdHBzZNIW0P/6+MhcMBqOgYBuXFJDp4es3tnMibvzDdntlIpH9wcx9T8RR5l+/EGb 6aWw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:message-id:date:from:user-agent:mime-version:to :cc:subject:references:in-reply-to:content-transfer-encoding; bh=PVqaB1SavaUPB1vasl4Nb3wwxUzBTfCxswU6AUGgUpw=; b=rNehqfY0K++CL2j25Ojxfz10UB0n9ZPCK5AtYwFt0hgkpWUr9f2fSqVL3lL4W55+bw f8dYV0Ws7UwRiXGisQlJDT+3oVWUXUk8HA+PFll9AM7tkXvcjlZjR6w1MV8Mur9apLqw zibyVeLhY95Y3TgyCqFGWK1QdUws7ydRz03TsI85CQojGhcopaxMKlN/dqGsRCN6i6Bo wnQBVlBOIRGFEAZUVnNUEFwGu37i0yNbBnlbmQqfphDZ1tsI/sAq+ij0PyCurq1rJHc5 g12hcQNUbCxpKXBmncUywoqjlY4JEllhSZP2NIAGg0i7VcDoTiK/VrUe/z3ru2PMZy1a IOXg== X-Gm-Message-State: AA+aEWY9wrqUyFPaQ/YYjfzMQB2qZQ8ezcKH8jqwqya1dhdJ9D8ArWyB FaTY+MpOWtFXxpVwBWG8gBA= X-Google-Smtp-Source: AFSGD/UEGO2i3Xp7oCLG+hCykoXLFIfwLxl5QKOlroKXPNLKlAxqPqfcQQ/gsUGtjJ3pu5wbPUF7CA== X-Received: by 2002:a02:660f:: with SMTP id k15mr169709jac.38.1544144019673; Thu, 06 Dec 2018 16:53:39 -0800 (PST) Received: from [10.0.10.7] (cpe-65-25-62-234.neo.res.rr.com. [65.25.62.234]) by smtp.googlemail.com with ESMTPSA id r21sm1293350ita.27.2018.12.06.16.53.38 (version=TLS1 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Thu, 06 Dec 2018 16:53:38 -0800 (PST) Message-ID: <5C09C491.1060803@gmail.com> Date: Thu, 06 Dec 2018 19:53:37 -0500 From: Ernie Luzar User-Agent: Thunderbird 2.0.0.24 (Windows/20100228) MIME-Version: 1.0 To: Polytropon CC: JD , freebsd-questions@freebsd.org Subject: Re: sh code to determine if host is on lan References: <5C099F41.2020407@gmail.com> <5C09AB7B.4010001@gmail.com> <20181207011905.af7d5c29.freebsd@edvax.de> In-Reply-To: <20181207011905.af7d5c29.freebsd@edvax.de> Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-Rspamd-Queue-Id: 391B56FB2B X-Spamd-Result: default: False [-2.41 / 15.00]; RCVD_VIA_SMTP_AUTH(0.00)[]; TO_DN_SOME(0.00)[]; FREEMAIL_FROM(0.00)[gmail.com]; R_SPF_ALLOW(-0.20)[+ip6:2607:f8b0:4000::/36]; RCVD_COUNT_THREE(0.00)[3]; MX_GOOD(-0.01)[cached: alt3.gmail-smtp-in.l.google.com]; DKIM_TRACE(0.00)[gmail.com:+]; DMARC_POLICY_ALLOW(-0.50)[gmail.com,none]; FROM_EQ_ENVFROM(0.00)[]; IP_SCORE(0.28)[ip: (4.34), ipnet: 2607:f8b0::/32(-1.54), asn: 15169(-1.31), country: US(-0.09)]; RCVD_TLS_LAST(0.00)[]; FREEMAIL_ENVFROM(0.00)[gmail.com]; ASN(0.00)[asn:15169, ipnet:2607:f8b0::/32, country:US]; MID_RHS_MATCH_FROM(0.00)[]; ARC_NA(0.00)[]; NEURAL_HAM_MEDIUM(-0.96)[-0.956,0]; R_DKIM_ALLOW(-0.20)[gmail.com]; FROM_HAS_DN(0.00)[]; RCPT_COUNT_THREE(0.00)[3]; NEURAL_SPAM_SHORT(0.26)[0.255,0]; NEURAL_HAM_LONG(-0.98)[-0.976,0]; MIME_GOOD(-0.10)[text/plain]; PREVIOUSLY_DELIVERED(0.00)[freebsd-questions@freebsd.org]; TO_MATCH_ENVRCPT_SOME(0.00)[]; RCVD_IN_DNSWL_NONE(0.00)[2.4.1.0.0.0.0.0.0.0.0.0.0.0.0.0.0.2.0.0.4.6.8.4.0.b.8.f.7.0.6.2.list.dnswl.org : 127.0.5.0]; FREEMAIL_CC(0.00)[gmail.com] 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: Fri, 07 Dec 2018 00:53:41 -0000 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. >>> >>> Is this the only way to determine if the host is on a lan? >>> >> I you do not want to know all that info you already >> stated, why don;t you ping something with a count of 1, >> such as yahoo.com: >> ping -c 1 yahoo.com >> [ $? -ne 0 ] && echo "not on internet" || echo "On Internet" > > I think this doesn't answer the initial question (which I'm > not sure I have understood correctly); the question is: Is > the system on a LAN ("networked, but not on the Internet")? > Of course to check _if_ it is somehow connected to the Internet, > a simple ping is sufficient, as long as you can make sure > an ICMP echo request and its reply is not blocked somewhere > within the firewall; it's also imporatant to use good values > for tumeout and wait reply time - just because something _does_ > answer a request too slow does not imply it cannot be reached. > > For example, I use something like this to check if a set of > hosts is currently up: > > # ping timeout (in seconds) = ping -t > TIMEOUT=2 > # time to wait for ICMP echo reply packets (in milliseconds) = ping -W > WAITREPLY=100 > # ... > ping -q -t ${TIMEOUT} -W ${WAITREPLY} -c 1 ${HOST} > /dev/null 2>&1 > if [ $? -eq 0 ]; then > # ... > > I use this for a status display and SSH connection selector. > Note that there is still a difference between "is up" and > "will accept a SSH connection". ;-) > > Similarly, you could use fetch (provided by OS), wget or > curl (additional ports) to get (and discard) a web page > you know is somewhere on the Internet. If your firewall > does only allow HTTP traffic, this would be a usable > solution. > > The route | grep | ifconfig | grep approach initially shown > does obtain lots of information, discards most of them, but > of course answers the question if the system is currently > configured for LAN. However, with _multiple_ interfaces, > for example one for LAN, one for Internet, things get much > more interesting. :-) > Connected to the internet is NOT the question. Is this host a node on the lan is the question. 192.168/16 or 172.16/12 or 10/8, these ip address ranges are non-routeable over the public internet. By standards they are reserved for lan addresses. If the host being inspected has been assigned one of these ip address would indicate its a node on the lan. Using a sh script is there a simpler way of finding this out without drilling down through those commands I posted above? What I am hearing so far is no there is short cut method. Thanks for your replies.