Report-IP icon indicating copy to clipboard operation
Report-IP copied to clipboard

interface names

Open mfisher87 opened this issue 11 years ago • 2 comments

Not every distribution uses the same interface names. Instead of eth0, I have enp2s0. Instead of providing the wlan0 and eth0 addresses, the script could loop over all network interfaces in /sys/class/net (except lo interface).

That way, if you have multiple ethernet interfaces or multiple wlan, you get them all. This is also pulling ipv6 address, but so does your original code. You collapse 2nd line with first when you echo without quotes.

$ for i in `ls /sys/class/net`; 
do 
echo "===$i==="
ip addr list $i | grep inet |cut -d' ' -f6|cut -d/ -f1
done
===eno1===
===enp2s0===
192.168.??.??
????::???:????:????:???
===lo===
127.0.0.1
::1

mfisher87 avatar Jun 09 '14 14:06 mfisher87

This wasn't meant to be distro agnostic, but I might work towards it. Thanks!

aneisch avatar Jun 09 '14 17:06 aneisch

Yeah. It's really cool that you shared your idea in either case, so thank you! I hadn't thought of something like this so it was fun to make it work in my own environment :)

mfisher87 avatar Jun 09 '14 20:06 mfisher87