Extract IPV4 IP Addresses out of file

Extract IPV4 IP Addresses out of file

Here's a very helpful method we can use to extract all IPV4 addresses out of a file, such as httpd.conf for for example.

sed -n  's/\([0-9]\{1,3\}\.\)\{3\}[0-9]\{1,3\}/\nip&\n/gp' /pathtofilehere | sed 's/ip//'

Running it on my local resolv.conf file, here's what some output will look like. Apache or any other daemon will look quite similar.

E-Rodriguezs-MacBook-Pro:/ erodriguez$ sed -n  's/\([0-9]\{1,3\}\.\)\{3\}[0-9]\{1,3\}/\nip&\n/gp' /etc/resolv.conf | sed 's/ip//'
nameserver 
8.8.8.8

nameserver 
8.8.4.4

nameserver 
207.210.208.138

nameserver 
207.210.211.118