With the following grep syntax I want to match all IP address in a file (from a ksh script)
grep '[0-9]\{1,3\}\.[0-9]\{1,3\}\.[0-9]\{1,3\}\.[0-9]\{1,3\}' file
The problem: It also matches words (IP) that have more then 4 octets:
1.1.1.1.1
or
192.1.1.1.160
How can I match a valid IP and only IP addresses with 4 octets? I can also use Perl – a one line syntax solution, if grep doesn't work.

999.999.999.999too. – cYrus Oct 24 '10 at 12:11192.1.1.1.160example: would you expect192.1.1.1or1.1.1.160or no match at all? – Arjan Oct 24 '10 at 12:54192.1.4097are valid and accepted by Linux glibc and Windows. – grawity Oct 24 '10 at 14:49