Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

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

Is there an nmap line that will auto-detect my current IP address and subnet mask, and run a ping-scan on all? For example:

#> nmap -sP

Instead of manually:

#> nmap -sP
share|improve this question
up vote 4 down vote accepted

I don't think that there is a way with doing that with nmap alone, but you could script it: Here is a quick and dirty solution:


IP_AND_MASK=`ifconfig | grep "inet addr" | head -n1 | sed 's|.*addr:\([0-9\.]*\).*Mask:\([0-9\.]*\)|\1/\2|g'`
NETWORK=`ipcalc "$IP_AND_MASK" | grep "Network:" | sed 's|^Network:\s*\([0-9/\.]*\).*|\1|g'`
nmap -sP "$NETWORK"

You have to install ipcalc to make that solution work.


share|improve this answer

This works, but then you still need to know your own subnet... saves copy-pasting the IP address though.

nmap -sP /24
share|improve this answer
On my system (OS X 10.10, nmap version 6.47) this doesn’t work for me. I get the following error: ::1/0 looks like an IPv6 target specification -- you have to use the -6 option.. – Daniel Griscom Jan 25 '15 at 21:13

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.