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,

Take a look at Network Manager/DBus -

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:

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.