Results 1 to 5 of 5

Thread: Using NMAP to ping IP addresses

  1. #1
    Just burned his ISO
    Join Date
    Nov 2007
    Posts
    2

    Question Using NMAP to ping IP addresses

    I am new to NMAP and want to use it to ping an ip range from 10.2.148.0 - 10.2.150.255. I want to be able to Ping Scan every computer in that address poll and if it returns a ping I want to output just the IP address of a computer with each additional ip address on a separate line.

    I have started out and got this far:

    nmap -v -sP 10.2.148.0/24 > c:\test.txt

    This script works for all ip addresses in the 148 range but when it outputs it there is a header and then loads of information about ping response times and pings that are dead, but all I want is pings that are alive each on a new line. I know this must be possible but after hours of reading I figured someone on here would know straight away.

    Any help would be amazing

    Thanks

    Chris

  2. #2
    Member Primey's Avatar
    Join Date
    Sep 2007
    Posts
    126

    Default

    im guessin you're running nmap on windows? because of the C:\test.txt

    and if i understood right, you want an output with the pings that are alive in that range

    i recommend using linux here, bash scripting can help a lot on the output file

    example:

    Code:
    cat test.txt | grep open | cut -d" " -f2 > 148-range.txt
    that gives you an output on the 148-range.txt file of all the ip's in the range, again, this is just an example, you might want to give a read or two to a bash scripting manual or tutorial

    might wanna start here

  3. #3
    My life is this forum thorin's Avatar
    Join Date
    Jan 2010
    Posts
    2,629

    Default

    If you're doing this in windows just do a batch file using a loop with:
    ping -n 1 <target>

    If %ERRORLEVEL% coming back from ping is 0 then the host was pingable, so write it to your output.

    Assume lst.txt contains your IP list (you can do nmap -sL 10.2.148.0/24 > lst.txt to generate the list)
    Code:
    @echo off
    
    for /f "tokens=*" %%I in (lst.txt) do call :pinger %%I
    goto :eof
    
    :pinger
    ping -n 1 %1 
    if %ERRORLEVEL% ==0 echo %1 >> pingLOG.txt
    :: DONE
    Now pingLOG.txt has a list of IPs that were pingable.
    I'm a compulsive post editor, you might wanna wait until my post has been online for 5-10 mins before quoting it as it will likely change.

    I know I seem harsh in some of my replies. SORRY! But if you're doing something illegal or posting something that seems to be obvious BS I'm going to call you on it.

  4. #4
    Senior Member streaker69's Avatar
    Join Date
    Jan 2010
    Location
    Virginville, BlueBall, Bird In Hand, Intercourse, Paradise, PA
    Posts
    3,535

    Default

    Quote Originally Posted by thorin View Post
    If you're doing this in windows just do a batch file using a loop with:
    ping -n 1 <target>

    If %ERRORLEVEL% coming back from ping is 0 then the host was pingable, so write it to your output.

    Assume lst.txt contains your IP list (you can do nmap -sL 10.2.148.0/24 > lst.txt to generate the list)
    Code:
    @echo off
    
    for /f "tokens=*" %%I in (lst.txt) do call :pinger %%I
    goto :eof
    
    :pinger
    ping -n 1 %1 
    if %ERRORLEVEL% ==0 echo %1 >> pingLOG.txt
    :: DONE
    Now pingLOG.txt has a list of IPs that were pingable.
    Damn, you are an old timer if you're writing things like that in Batch files. Most kidlings today don't know what a batch file is.
    A third party security audit is the IT equivalent of a colonoscopy. It's long, intrusive, very uncomfortable, and when it's done, you'll have seen things you really didn't want to see, and you'll never forget that you've had one.

  5. #5
    Just burned his ISO
    Join Date
    Nov 2007
    Posts
    2

    Default

    Thanks for all your help guys worked a treat! I think I will stick with the nmap at the moment as windows ping takes a while.


    Cheers again

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •