Ask Ubuntu is a question and answer site for Ubuntu users and developers. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top
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 '14 at 16:34
up vote 4 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

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

I would do this using just grep:

$ sudo arp-scan --interface=eth0 --localnet | grep -oP '^[\d.]+'


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

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}'

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 '14 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 '14 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 '14 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 '14 at 19:02
I just tried on my 13.10 VM and it worked fine: echo " 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 '14 at 19:03

Your Answer


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.