Network Connectivity
Vu Pham
vu at sivell.com
Fri Aug 10 07:08:02 PDT 2012
On 08/10/2012 02:14 AM, Steve Jardine wrote:
> All,
>
> Does anyone have an idea as to how to determine if any device has network connectivity. Where devices are WiFi (wlan0), Ethernet (Eth0), Wireless (usb0-2)? I need to trigger an event if network connectivity exists.
>
> Steve
>
Two places I will look at :
1. /sys/class/net
- Each network device has a separate directory.
[vu at vpepper ~]$ ls /sys/class/net
eth0 eth1 lo sit0
- Each of these directories has files that contain information about
that device, including the network connectivity.
[vu at vpepper ~]$ ls /sys/class/net/eth0
address device ifindex operstate statistics uevent
addr_len dormant iflink rxbuf_cur subsystem weight
broadcast features link_mode rxbuf_max tx_queue_len
carrier flags mtu rxbuf_min type
- the file operstate shows that current status of the device.
[vu at vpepper ~]$ cat /sys/class/net/eth0/operstate
up
Other files such as carrier, iflink ... may help, too.
2. udev: the udev scripts can change your device names, or to make it
consistent.
If you want the LAN devices always ethX , no matter what drivers they
use, then udev scripts can help.
Vu
More information about the Linux-users
mailing list