Date: Thu, 06 Dec 2018 19:53:37 -0500 From: Ernie Luzar <luzar722@gmail.com> To: Polytropon <freebsd@edvax.de> Cc: JD <jd1008@gmail.com>, freebsd-questions@freebsd.org Subject: Re: sh code to determine if host is on lan Message-ID: <5C09C491.1060803@gmail.com> In-Reply-To: <20181207011905.af7d5c29.freebsd@edvax.de> References: <5C099F41.2020407@gmail.com> <5C09AB7B.4010001@gmail.com> <20181207011905.af7d5c29.freebsd@edvax.de>
next in thread | previous in thread | raw e-mail | index | archive | help
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.
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?5C09C491.1060803>