10

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 0.0.0.0

Instead of manually:

#> nmap -sP 192.168.100.0/24

3 Answers 3

6

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:

#!/bin/bash

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.

hth

2

Mileage may vary, but this should work well in most circumstances...

nmap -sP `hostname -I | sed 's/[0-9]\+\s/0\/24 /g'`
1
  • It will work if my subnet is /24 which for most homes it, but for some corporate environment isn't. Good tip though! I like it. Commented Aug 18, 2018 at 11:19
-1

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

nmap -sP /24
3
  • 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.. Commented Jan 25, 2015 at 21:13
  • 1
    Does not work on ubuntu 18.04. Need to specify the network ID address
    – pcnate
    Commented Jun 7, 2018 at 17:58
  • try: nmap -sP 10.0.0.0/24 or maybe nmap -sP 192.168.0.0/24 works on macOS also
    – Tomachi
    Commented Oct 22, 2019 at 11:13

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .