![]() |
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. |
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. |
Re: How Can I Tell I'm Connected to the Network?
Quote:
Code:
if [ "x`/sbin/ifconfig wlan0 |grep UP`" != x ] ; then Code:
if [ "x`/sbin/ifconfig wlan0 |grep UP`" != x ] || [ "x`/sbin/ifconfig bt0 |grep UP`" != x ] ; then |
Re: How Can I Tell I'm Connected to the Network?
Quote:
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... |
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. |
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