From owner-freebsd-questions@freebsd.org Fri Dec 7 00:19:16 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 634451321DBD for ; Fri, 7 Dec 2018 00:19:16 +0000 (UTC) (envelope-from freebsd@edvax.de) Received: from mout.kundenserver.de (mout.kundenserver.de [212.227.126.135]) (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 7ED846DA64 for ; Fri, 7 Dec 2018 00:19:15 +0000 (UTC) (envelope-from freebsd@edvax.de) Received: from r56.edvax.de ([92.193.252.129]) by mrelayeu.kundenserver.de (mreue009 [212.227.15.167]) with ESMTPA (Nemesis) id 1N7Qp3-1hXYAB0h5R-017lKK; Fri, 07 Dec 2018 01:19:06 +0100 Date: Fri, 7 Dec 2018 01:19:05 +0100 From: Polytropon To: JD Cc: freebsd-questions@freebsd.org Subject: Re: sh code to determine if host is on lan Message-Id: <20181207011905.af7d5c29.freebsd@edvax.de> In-Reply-To: <5C09AB7B.4010001@gmail.com> References: <5C099F41.2020407@gmail.com> <5C09AB7B.4010001@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:KA4YiFGiJNvZtu4Jpsv1xDE4K2rEVygGf+CvywETJ8jekSScT9N sGqVjL4Gqop17i8SXmXeNAn5zb1iwbCC1xmVtHWET72pwPLybeWgdmslrZ9iJnnkbFz55L1 Khqg93Tower9PVzG3lftU7GZ/y9oRdNSvhN+O78yqyjVZvKvcwSJnLKvf6+mNnEPLma0JnC GBxsifGlSkl+K7QqiC2qw== X-Spam-Flag: NO X-UI-Out-Filterresults: notjunk:1;V03:K0:U5mLjHDXNEs=:FhHF8t8XI9ELwVFAd3gtZ/ Ic5hCaD19iI2aaNtRtzKI3PoW6wijIBz11IGycLlp9pGSybfro7Dcqm1Zo8BhDow6BMiN3esL If8AOjoCKKSVs4dd0sfG7JWV+Bc5vNVOMCd8XgOMGHQ6yUXy7iOKQuY530I9gXRYU6uAh2z9Z KdCL5BmiVPLdjcqg+Ahesj6pB6mxsx6q/xnsV5BJ1vuMUS0QNu1F/qhBFWfy1f0LesBQLwu44 +SPu+uvPexYXSc6YGibUC0R7ZiqFNFV/k+CefhZseu0GCiGS+qqybpbvr9TtESdCqeUh6OIzg Z3egG3PBp9dXCASYtxSmJsJpWE5qgxPZhujUlz5qAO59tY8FUgMfCcAH38zwq365jOMiww4Co gzwkTsCP4y6XRCu7RzFAwi4bNYOaFIgaN7lMwEUQCqXap6In+15doqFlC9kkZtlT6VRmr8Q0d TV4BQe4wuIgdfJi5zjDaQwmZcsTji+GgZC7xaGmuxi7OKrgLP94k5w5OqeDhBK0c+UKX5WDj4 bZP8JZC5uTyp4e3o7jkvQ4xjM8CV9AgqClO8BbRbv8y2Fn/dJdMf9R/9J7j/duCqg62ukOIpw UUQKBF8ySHutlMtmL4ThhiZh5a42Y9CjPz6IPZQ7Ncls+9cxG0M5W67k1f4in2oCZiqPlULjU 7y3TVY3bWxCKFNCv8GTwq1lLlKpMhxH7RrCldCJEvntwn41s0DqXqDVv6NgYciH/k7A+7agBn jDRI+t1ysQEhERJaShIiZFVOWgXTS/77A7rssMEyfQxIaOJBKJP2Ru7Bn4g= X-Rspamd-Queue-Id: 7ED846DA64 X-Spamd-Result: default: False [0.13 / 15.00]; RCVD_VIA_SMTP_AUTH(0.00)[]; HAS_REPLYTO(0.00)[freebsd@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]; NEURAL_HAM_SHORT(-0.23)[-0.226,0]; 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.92)[-0.922,0]; REPLYTO_EQ_FROM(0.00)[]; FROM_HAS_DN(0.00)[]; NEURAL_HAM_LONG(-0.97)[-0.968,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)[135.126.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: Fri, 07 Dec 2018 00:19:16 -0000 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. :-) -- Polytropon Magdeburg, Germany Happy FreeBSD user since 4.0 Andra moi ennepe, Mousa, ...