Find IP address and the corresponding interface in a Linux system

Started by Dieselboy, November 21, 2019, 11:55:06 PM

Previous topic - Next topic

Dieselboy

Doing more with systems that do routing as well as openwrt. Sometimes they have lot of IP addresses. Wanted to match the interface with the IP. Tried to do this myself, which worked but not really:

ip addr | grep [0-9.+]\.[0-9.+]\.[0-9.+]\.[0-9.+]

Then found this which works a treat:

ip addr | grep -E "([0-9]{1,3}[\.]){3}[0-9]{1,3}"


Taken from https://www.shellhacks.com/regex-find-ip-addresses-file-grep/

Dieselboy

I was trying to find if anyone is logged in to Openstack. I came back here to grab the IP address grep and made this:

ss -an | grep ESTAB | grep -vE '192.168.17.|192.168.18.|127.0.0' | grep -E "([0-9]{1,3}[\.]){3}[0-9]{1,3}"

ss -an shows the connections
grep -v is inverse and E is extended. This means that '192.168.17.|192.168.18.|127.0.0' is filtering out lines with these (I dont care about connections to 127.0.0.1 for example)

The last section is there to just show me the ip addresses. I was getting "/var/something" data returned with the ss -an.