How to determine the NIC port state? (cable plugged yes/no, link yes/no, etc)

ifconfig -a would show all. It is now left to your interpretation e.g. check tx and Rx packets, if nic is full or half duplex etc.
Thank You!

I just try to make .php with NIC's current state displaying.
May be Yaoundé suggest me some ready-to-use packet ?
 
Code:
root@jigoku:/ # ifconfig -a
bge0: flags=8843<UP,BROADCAST,RUNNING,SIMPLEX,MULTICAST> metric 0 mtu 1500
options=c019b<RXCSUM,TXCSUM,VLAN_MTU,VLAN_HWTAGGING,VLAN_HWCSUM,TSO4,VLAN_HWTSO,LINKSTATE>
    ether b0:0b:de:ad:b0:0b
    inet 192.168.1.7 netmask 0xffffff00 broadcast 192.168.1.255
    media: Ethernet autoselect (100baseTX <full-duplex>)
    status: active
    nd6 options=29<PERFORMNUD,IFDISABLED,AUTO_LINKLOCAL>
lo0: flags=8049<UP,LOOPBACK,RUNNING,MULTICAST> metric 0 mtu 16384
options=680003<RXCSUM,TXCSUM,LINKSTATE,RXCSUM_IPV6,TXCSUM_IPV6>
    inet6 ::1 prefixlen 128
    inet6 fe80::1%lo0 prefixlen 64 scopeid 0x2
    inet 127.0.0.1 netmask 0xff000000
    groups: lo
    nd6 options=21<PERFORMNUD,AUTO_LINKLOCAL>
pflog0: flags=141<UP,RUNNING,PROMISC> metric 0 mtu 33160
groups: pflog


Get Spoofy With It

Mine show 100baseTX full-duplex on that machine and this one.
 
When you want to see the status of interfaces you typically want to look at them all, regardless if they're administratively down or not. When scripting, the output from ifconfig -l can be useful to loop over each interface individually.

Something like this:
Code:
interfaces=$(ifconfig -l)
for iface in ${interfaces}; do
  echo -n "${iface}:"
  ifconfig ${iface} | grep 'status:'
done

Note that this script screws up with lo0 because it has no status, it's always 'connected'.
 
Back
Top