Take the 2-minute tour ×
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free, no registration required.
sudo arp-scan --interface=eth0 --localnet

I know the above command works fine but it outputs everything like MAC address etc, etc. But I need to find only IP addresses. Is it possible ?

share|improve this question
    
Use grep to filter your output (or perl or awk .... ) –  bodhi.zazen Mar 18 at 16:34
add comment

3 Answers 3

up vote 3 down vote accepted

I just used awk,tail and head to achieve what you want:

sudo arp-scan --interface=eth0 --localnet| awk '{print $1}'|tail -n +3|head -n -2

this gives the output as

192.168.1.1
192.168.1.3

as I have only these two in my Lan.

Here awk '{print $1}' prints the ip address which is situated in the first column. tail and head removes unnecessary stuff like the header and just shows the ip addresses.

share|improve this answer
add comment

Here is a one liner to get the IP address using the ifconfig command:

~$ ifconfig eth0 | grep 'inet addr:' | cut -d: -f2 | awk '{ print $1}'
192.168.1.10

Does that do what you wanted? Or did you need the arp-scan command?

I re-read and see I missed the point of the question. arp-scan shows the local IP addresses for the network and I only showed the IP of the machine with ifconfig. Below is a version of the above terdon solution only not using the PCRE library. Ubuntu had an issue with pcre and grep when I tried it.

$ sudo arp-scan --interface=eth0 --localnet | grep -o ^[0-9.]*
share|improve this answer
    
You are correct. I see what he was asking now. –  Michael McGarrah Mar 18 at 17:48
    
Thanks for the edit! Have an upvote. What was the problem on Ubuntu? I tested mine on Debian so there may well be a difference. –  terdon Mar 18 at 18:46
    
I tried the -P and didn't get the pcre support working for me. I'm on Ubuntu 12.04.3 and 12.10. Tried pcregrep as well and it wasn't happy. I'm digging some more on my setup because I like Perl syntax better for grep. Perl was the first regex I used so I have a soft spot for it. –  Michael McGarrah Mar 18 at 19:01
    
I'm using this to scan my local network and finding some interesting systems I hadn't documented. Glad this question came up. –  Michael McGarrah Mar 18 at 19:02
    
I just tried on my 13.10 VM and it worked fine: echo "1.2.3.44.5 ljasd asdlnasd " | grep -Po '[\d.]+'. Make sure you quote the pattern: '[\d.]+'. And of course you like PCREs, they're by far the best regex flavor around! :) –  terdon Mar 18 at 19:03
show 3 more comments

I would do this using just grep:

$ sudo arp-scan --interface=eth0 --localnet | grep -oP '^[\d.]+'
192.168.0.1 
192.168.0.2 
192.168.0.3 
192.168.0.10    
192.168.0.23    
192.168.0.72    
192.168.27.1    
192.168.27.14
192.168.27.30

Explanation:

The -P tells grep to use Perl Compatible Regular Expressions, where \d matches any number. The -o means "print only the matching part of the line". The regular expression I used means match the longest string (that's what the + means) of consecutive numbers (\d) or dots (.) that are at the beginning of the line (^).

share|improve this answer
add comment

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.