find-ip — Finding files containing an IP address

Download find-ip.sh

#!/bin/sh
#
# find-ip.sh - A script to list the names of files under
# /etc that contain the current host's (primary) IP address.
# This can be useful if you ever need to change it.
# A similar script could be used to find files containing
# any string.
#
# Written 3/2007 by Wayne Pollock, Tampa Florida USA.

# Find the current host's ipaddress.  This can be
# done in several ways, but looking up the hostname,
# then using host to do a reverse DNS lookup on that
# name seems the most portable way to find the
# primary IP address in case the host has more than one:

ipaddr=$(host `hostname` | awk '{print $NF}')

#echo "Files under /etc that contain \"$ipaddr\":"

# Now we find regular files under /etc, and grep them:

find /etc -type f 2>/dev/null | xargs grep -l $ipaddr 2>/dev/null