I am looking to retrieve a list of network interfaces.
Currently I am returning the results of ip addr
and then doing some regex/string searching from output like this:
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN group default qlen 1
link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
inet 127.0.0.1/8 scope host lo
valid_lft forever preferred_lft forever
inet6 ::1/128 scope host
valid_lft forever preferred_lft forever
84: eth0@if85: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc noqueue state UP group default
link/ether 02:42:ac:11:00:02 brd ff:ff:ff:ff:ff:ff
inet 172.17.0.2/16 scope global eth0
valid_lft forever preferred_lft forever
inet6 fe80::42:acff:fe11:2/64 scope link tentative
valid_lft forever preferred_lft forever
I don't really care about all the meta data, I am just looking for the interface names. So I would like to instead get:
1: lo
84: eth0@if85
Is there a way to filter the results of the ip addr
command? I can definitely do some other cli magic or just regex magic in my app, but it'd be nice to have ip
itself filter.