There are many ways to get networking information on your Linux computer.
This is how to return the active network interface(s) on your Linux system.
4.4 Mon Jun 22 jason@Yog-Sothoth 0: $ ip addr | awk '/state UP/ {print $2}' | sed 's/.$//' enp0s25
Combining this command with another using backticks, it is possible to get the IP address of the active network interface easily.
4.4 Mon Jun 22 jason@Yog-Sothoth 0: $ ip -f inet -o addr show `ip addr | awk '/state UP/ {print $2}'` | cut -d\ -f 7 | cut -d/ -f 1 192.168.1.2
This would, of course, be very useful in a script, but then you could use variables to hold the interface value and then use that in the second part of the script. Just like the example below. This will get the IP address and interface name on your Linux computer and print the result.
1 2 3 4 5 6 7 8 9 | #!/bin/sh interface=$(ip addr | awk '/state UP/ {print $2}' | tr [:] ' ') address=$(ip -f inet -o addr show $interface | cut -d\ -f 7 | cut -d/ -f 1) if [ -z "$address" ]; then echo "No IP address assigned on your machine." else echo "Your IP address is: $address. This is applied to the \"$interface\" networking interface." fi |
A very useful networking script.
Another very useful utility is iptraf-ng. This will print information about network connections on your network. This works in promiscuous mode, and as such cannot determine the socket statuses for other machines on the LAN. But this gives a good indication of what is going on with your network.
This could be a very good companion to Wireshark.
Run it like this.
4.4 Mon Jun 22 jason@Yog-Sothoth 0: $ sudo iptraf-ng |
It is menu-driven and very easy to use.