Welcome to the MacNN Forums.

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

You are here: MacNN Forums > Software - Troubleshooting and Discussion > macOS > Discover network status from CLI?

Discover network status from CLI?
Thread Tools
wataru
Addicted to MacNN
Join Date: Oct 2001
Location: Yokohama, Japan
Status: Offline
Reply With Quote
May 25, 2005, 09:50 AM
 
I want to be able to tell whether or not the network is up from the CLI. I suppose I could just ping something and wait for it to time out, but that seems like a bad solution. Anyone know if this is stored as a paramter readable with defaults or something?
     
OreoCookie
Moderator
Join Date: May 2001
Location: Hilbert space
Status: Offline
Reply With Quote
May 25, 2005, 10:14 AM
 
First would be ifconfig. ifconfig tells you what kind of connection you have, if any, which speed, whether or not duplex is active, the ip, etc.

If you get a 169.x.x.x ip, your computer couldn't find a dhcp server and assigned this ip to itself (windows does the same).

Then you could check whether or not you can find a name server. Enter nslookup www.apple.com and you should get Apple's server's ip address.

What else are you trying to find out?
I don't suffer from insanity, I enjoy every minute of it.
     
wataru  (op)
Addicted to MacNN
Join Date: Oct 2001
Location: Yokohama, Japan
Status: Offline
Reply With Quote
May 25, 2005, 10:21 AM
 
I just want to find out if the machine has access to the internet. ifconfig has plenty of info, but not a simple boolean about whether the network is up or down.

I suppose host will do (nslookup is deprecated). Thanks.
     
OreoCookie
Moderator
Join Date: May 2001
Location: Hilbert space
Status: Offline
Reply With Quote
May 25, 2005, 10:47 AM
 
Yes, ifconfig delivers you exactly that: if there is a physical connection, you will see a speed and an ip. If you don't have a connection, it'll just show you the MAC address and the speeds available.

nslookup still works in Tiger, but you can also use dig. dig www.apple.com.
I don't suffer from insanity, I enjoy every minute of it.
     
wataru  (op)
Addicted to MacNN
Join Date: Oct 2001
Location: Yokohama, Japan
Status: Offline
Reply With Quote
May 25, 2005, 11:46 AM
 
Yeah but then I still have to parse it more carefully than a simple "network-status=up" or something. Plus a physical connection doesn't necessarily mean an internet connection, which is what I really want. (No, I didn't really specify that before. Sorry.)

I know nslookup works, but it warns you when you run it that it's deprecated. I like to try to futureproof my apps.

I tried dig, but the output of host ended up being easier to parse. Thanks for the tip, though.
     
OreoCookie
Moderator
Join Date: May 2001
Location: Hilbert space
Status: Offline
Reply With Quote
May 25, 2005, 12:03 PM
 
It's mainly because there are so many levels of `is this working'.

Take a look at Apple's Connection Doctor. I think they have seven different stages or so.
I don't suffer from insanity, I enjoy every minute of it.
     
Kristoff
Mac Elite
Join Date: Sep 2000
Location: in front of the keyboard
Status: Offline
Reply With Quote
May 25, 2005, 01:50 PM
 
Originally Posted by wataru
Yeah but then I still have to parse it more carefully than a simple "network-status=up" or something. Plus a physical connection doesn't necessarily mean an internet connection, which is what I really want. (No, I didn't really specify that before. Sorry.)
You can't possibly know if you have an internet connection unless you attempt to connect and it either works, or times out.

You can be connected to a private lan, and ifconfig will show the link status, but you still wont have an internet connection.
signatures are a waste of bandwidth
especially ones with political tripe in them.
     
Xtraz
Forum Regular
Join Date: May 2000
Status: Offline
Reply With Quote
May 26, 2005, 04:03 PM
 
seems like you should just do a ping to www.google.com and see if it responds
     
wataru  (op)
Addicted to MacNN
Join Date: Oct 2001
Location: Yokohama, Japan
Status: Offline
Reply With Quote
May 26, 2005, 10:28 PM
 
Actually I'm doing host www.google.com, but the result is similar
     
Detrius
Professional Poster
Join Date: Apr 2001
Location: Asheville, NC
Status: Offline
Reply With Quote
May 27, 2005, 12:50 AM
 
Originally Posted by wataru
Actually I'm doing host www.google.com, but the result is similar
Depending on where your DNS server is located, a successfully name resolution doesn't necessarily mean you are on the internet. For example: if the DNS server is the router, but the routing functionality has failed, you will still be able to do name resolution, but you won't be able to ping, as those packets will be dropped.
ACSA 10.4/10.3, ACTC 10.3, ACHDS 10.3
     
Kristoff
Mac Elite
Join Date: Sep 2000
Location: in front of the keyboard
Status: Offline
Reply With Quote
May 27, 2005, 11:24 AM
 
Hehehe.....Detrius, that's a pretty contrived situation, eh?

But, more likely is that you had full connectivity, and lookupd has cached the results, and at some later point you no longer have connectivity, but the name will still resolve due to the cached value.

So, that's two ways that using host isn't the best option for checking realtime internet connectivity.
signatures are a waste of bandwidth
especially ones with political tripe in them.
     
wataru  (op)
Addicted to MacNN
Join Date: Oct 2001
Location: Yokohama, Japan
Status: Offline
Reply With Quote
May 27, 2005, 12:21 PM
 
Ok, ok, I'll use ping. You guys are pushy
     
   
 
Forum Links
Forum Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Top
Privacy Policy
All times are GMT -4. The time now is 07:03 PM.
All contents of these forums © 1995-2017 MacNN. All rights reserved.
Branding + Design: www.gesamtbild.com
vBulletin v.3.8.8 © 2000-2017, Jelsoft Enterprises Ltd.,