How to recursively find ip-addresses in all files under a specified directory.


A quick one line command that will find ip-addresses but will also find ip-address type strings that contain numbers larger than 255

Substitute the directory "/home" for the directory you would like to search


find /home -type f | xargs  grep  '[0-9]\{1,3\}\.[0-9]\{1,3\}\.[0-9]\{1,3\}\.[0-9]\{1,3\}'


This script is more complicated but will filter out a lot more non ip-address strings

Send the standard output to a script named findip.out, because in this script we prevent searching for ip-addresses in the output file findip.out

find / -type f -print | grep -v findip.out | while read FILE
    strings -a -n8 $FILE | \
    tr -cs '[0-9.]' '[\n*]' | \
    grep "[0-9]\{2,3\}\.[0-9]\{1,3\}\.[0-9]\{1,3\}\.[0-9]\{1,3\}" | \
    sed "s=^.*\$=$FILE      &="
done | awk -F"\t" '{n=split($2,octets,".")
if (n==4)
   for (octet in octets)
   if((octets[octet]>=0)&&(octets[octet]<=255)) good++
   if(good==4) print $0