This useful shell script will print information about your Ethernet or Wireless adapter. This is very useful for getting a lot of information at once.
#!/bin/sh DEV="eno16777736" echo "Showing information for the active network interface: $DEV." echo -e "-*- \e[1mGet timestamping information for your Ethernet device.\e[0m -*-" echo ethtool -T $DEV echo -e "-*- \e[1mPrinting main information about the Ethernet device.\e[0m -*-" echo ethtool $DEV echo -e "-*- \e[1mPrinting out the permanent hardware address.\e[0m -*-" ethtool -P $DEV echo echo echo -e "-*- \e[1mPrinting Ethernet adapter IP address.\e[0m -*-" ip a | awk '/inet / { print $2 }' | sed -n 2p |
This script uses the ethtool command. This is very good for gaining IP address info as well as other useful information.
The ethtool command prints verbose information about your network adapter.
Here is an example, this is returning information about a Ethernet card.
4.4 Wed Aug 07 jason@Yog-Sothoth 0: $ ethtool enp0s25 Settings for enp0s25: Supported ports: [ TP ] Supported link modes: 10baseT/Half 10baseT/Full 100baseT/Half 100baseT/Full 1000baseT/Full Supported pause frame use: No Supports auto-negotiation: Yes Supported FEC modes: Not reported Advertised link modes: 10baseT/Half 10baseT/Full 100baseT/Half 100baseT/Full 1000baseT/Full Advertised pause frame use: No Advertised auto-negotiation: Yes Advertised FEC modes: Not reported Speed: 1000Mb/s Duplex: Full Port: Twisted Pair PHYAD: 1 Transceiver: internal Auto-negotiation: on MDI-X: on (auto) Cannot get wake-on-lan settings: Operation not permitted Current message level: 0x00000007 (7) drv probe link Link detected: yes |
Print just the IP address of your network adapter.
ip a | awk '/inet / { print $2 }' | sed -n 2p |