Detect active connection: ethernet and/or wifi?

How can I detect:
a) If Cat5 ethernet has a live connection (to, say, a switch/router, though perhaps not to the internet)
b) If wifi has a live connection to
i) AP
ii) internet
c) If both ethernet and wifi are present, which adapter is the one I’m currently using?

Many thanks,
-Dave

Take a look at Network Manager/DBus - http://dev.iachieved.it/iachievedit/gauging-wireless-ap-stability-with-a-beaglebone-black/

Disclaimer: I’m the author of above post, but it shows how I detect Ethernet/Wifi.

Eek - its this one, but I’m using a Pi:

http://dev.iachieved.it/iachievedit/exploring-networkmanager-d-bus-systemd-and-raspberry-pi/

Do an

ls /sys/class/net
The eth device will always be there; you can tell if it has a cable connected by
sudo ip link dev eth0 up
and looking at the output.
There will also be a wlanx device in /sys/class/net if and only if a WiFi dongle is plugged in.