This little program for checking the NIC linked status in linux and OSX which I've tested already, and this is a extremely simple via popen to get the string that difference between linked and unlinked, another way is using SIOCGMIIREG via ioctl to check the MII data struct.
This one has linked.
eth0 Link encap:Ethernet HWaddr 74:l4:35:2d:8f:lb inet addr:192.168.1.80 Bcast:192.168.1.255 Mask:255.255.255.0 inet6 addr: fe80::76d4:35ff:fe2d:8f9b/64 Scope:Link UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1 RX packets:492606 errors:0 dropped:1 overruns:0 frame:0 TX packets:254456 errors:0 dropped:0 overruns:0 carrier:0 collisions:0 txqueuelen:1000 RX bytes:399268030 (399.2 MB) TX bytes:83955061 (83.9 MB)
This one has not linked.
eth0 Link encap:Ethernet HWaddr 74:l4:35:2d:8f:lb inet addr:192.168.1.80 Bcast:192.168.1.255 Mask:255.255.255.0 inet6 addr: fe80::76d4:35ff:fe2d:8f9b/64 Scope:Link UP BROADCAST MULTICAST MTU:1500 Metric:1 RX packets:492606 errors:0 dropped:1 overruns:0 frame:0 TX packets:254456 errors:0 dropped:0 overruns:0 carrier:0 collisions:0 txqueuelen:1000 RX bytes:399268030 (399.2 MB) TX bytes:83955061 (83.9 MB)
The RUNNING exists in netwoking linked, not exist in networking unlinked.
en0: flags=8863 mtu 1500 ether 28:cf:e9:1b:53:l9 inet6 fe80::2acf:e9ff:felb:5309%en0 prefixlen 64 scopeid 0x4 inet 192.168.1.104 netmask 0xffffff00 broadcast 192.168.1.255 nd6 options=1 media: autoselect status: active
en0: flags=8823 mtu 1500 ether 28:cf:e9:lb:53:l9 nd6 options=1 media: autoselect () status: inactive
Obviously, status field is difference between wifi on and wifi off.
So, that's write a function to check the status when we need.