Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

hi dear friends and good morning

The following question may be complicated and critical for my systems

I have 4 Linux machines with cluster

My target is to find all kind of IP address (xxx.xxx.xxx.xxx) in every file in the linux system

remark: need to scan each file in the linux system and verify if the file include IP address if yes need to print the IP

as the following

more /etc/inet/file.example1

 182.23.2.4
 255.255.0.0
 10.10.1.1
 19.2.*.*
 127.0.0.1

more /etc/dir/file1.example2

 1.1.1.1 TCP

Etc.................

Can I get some creative suggestion that search all IP address and print them

lidia

share|improve this question

1 Answer 1

up vote 1 down vote accepted

This will print the full line that contains something that resembles an IP address. It doesn't check to see if its octets are in the range 0-255.

grep -Er '\<([0-9]{1,3}\.){3}[0-9]{1,3}\>' /*

to only print the address without the rest of the line add the -o option. To disable printing the filename add the -h option.

You could replace the \< and \> delimiters with [[:space:]].

Edit:

Here's one that may be suitable for cases that include asterisks:

grep -Er '[[:space:]]((\*|[0-9]{1,3})\.){3}(\*|[0-9]{1,3})[[:space:]]' /*
share|improve this answer
    
little problem if the IP is for example 3.3.*.* can your syntax support this? –  lidia Sep 7 '10 at 8:29
    
@lidia: see my edit –  Dennis Williamson Sep 7 '10 at 9:25

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.