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



## Sergei_Shablovsky (Jun 29, 2021)

Dear BSD gurus!

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

Thank You all!


----------



## Alain De Vos (Jun 29, 2021)

"ifconfig -au" shows some info ?


----------



## Lamia (Jun 29, 2021)

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.


----------



## Sergei_Shablovsky (Jun 29, 2021)

Lamia said:


> 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 ?


----------



## Deleted member 30996 (Jun 30, 2021)

```
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.


----------



## SirDice (Jun 30, 2021)

Sergei_Shablovsky said:


> cable plugged yes/no, link yes/no, 10/100/1000 speed link, etc


You can't tell if a cable has been plugged in or not. You can tell if the link is active, look at the `status:` field. Speed and duplex settings are in `media`.


----------



## Alain De Vos (Jun 30, 2021)

```
ifconfig -au | egrep -i "status|media|flags"
```


----------



## SirDice (Jun 30, 2021)

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:

```
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'.


----------

