starting my answer based on this answer:
Yes , You have lot of options/tools to use. I just tried this , it
works:
ifconfig | grep -oE "\b([0-9]{1,3}.){3}[0-9]{1,3}\b"
a
so you can use grep -oE "\b([0-9]{1,3}.){3}[0-9]{1,3}\b" to grep the
ip addresses from your output.
and converting the answer to full length IPv6, etc...:
fgrep -oE "\b([0-9A-Fa-f]{1,4}:){7}[0-9A-Fa-f]{1,4}\b" -- file
if you want to keep the /nnn if it's there:
fgrep -oE "\b([0-9A-Fa-f]{1,4}:){7}[0-9A-Fa-f]{1,4}(/[0-9]{1,3}){0,1}\b" -- file
and also there's the shortened version of IPv6 that includes '::'.
for more IPv6 answers you can look here:
http://stackoverflow.com/questions/53497/regular-expression-that-matches-valid-ipv6-addresses
0010.0000.0000.0001
? May the file otherwise contain things that look like IP addresses like version numbers (soft-1.2.1100.1.tar.gz
, network specifications (10.0.0.0/24), 1.2.3.4.5)? Would you accept a solution that is positive on 333.444.555.666? Or0377.0377.0377.0377
(a valid quad-octal IP address)? – Stéphane Chazelas yesterday