maemo.org - Talk

maemo.org - Talk (https://talk.maemo.org/index.php)
-   Applications (https://talk.maemo.org/forumdisplay.php?f=41)
-   -   How Can I Tell I'm Connected to the Network? (https://talk.maemo.org/showthread.php?t=17745)

frethop 2008-03-10 17:57

How Can I Tell I'm Connected to the Network?
 
Simple question: Is there a way to tell from the command shell if I a connected to a network or not?

It's probably something in /proc...but I'm not finding it. I'm hoping this works for both wireless and mobile phone connections.

Thanks.

Edit: BTW, I DID search through the forums, but did not find anything. I'll not be surprised if someone has asked this already.

brendan 2008-03-10 18:19

Re: How Can I Tell I'm Connected to the Network?
 
/sbin/ifconfig wlan0

will give you an IP address, if you are connected. also, the RX/TX counters will not be 0. you should not need root access for this.

Benson 2008-03-10 18:34

Re: How Can I Tell I'm Connected to the Network?
 
Quote:

Originally Posted by brendan (Post 153088)
/sbin/ifconfig wlan0

will give you an IP address, if you are connected. also, the RX/TX counters will not be 0. you should not need root access for this.

Don't know what exact result you're after; if you want to use it in a shell conditional, grep it for UP, like this for wlan0:
Code:

if [ "x`/sbin/ifconfig wlan0 |grep UP`" != x ] ; then
  echo 'Connection'
else
  echo 'No connection'
fi

I don't know what interface BT connections show up as; but something like (if it were bt0):
Code:

if [ "x`/sbin/ifconfig wlan0 |grep UP`" != x ] || [ "x`/sbin/ifconfig bt0 |grep UP`" != x ] ; then
  echo 'Connection'
else
  echo 'No connection'
fi


aleksandyr 2008-03-10 18:40

Re: How Can I Tell I'm Connected to the Network?
 
Quote:

Originally Posted by brendan (Post 153088)
/sbin/ifconfig wlan0

will give you an IP address, if you are connected. also, the RX/TX counters will not be 0. you should not need root access for this.

This doesn't help you if you're not using wlan :)

Frethop, check out libconic. There's a DBUS call you can make that will report back what you're connected to (if anything). I'll try to get you a command line in a bit...

frethop 2008-03-10 19:24

Re: How Can I Tell I'm Connected to the Network?
 
Thanks everyone!

Actually, I'm going to use it in a Python program --> do one thing if connected, store results for use later if not.

m_stolle 2008-03-10 19:28

Re: How Can I Tell I'm Connected to the Network?
 
netstat -rn | grep '0\.0\.0\.0'

should work too. Basically, it checks the kernel's routing tables to see if there's a default gateway set. Without a default gateway, you can't connect to any systems outside your local ethernet segment, hence no connection. This is indifferent to the kind of connection you use - BT, WLAN or whatever.

Martin


All times are GMT. The time now is 14:34.

vBulletin® Version 3.8.8