→ 🚀What's New? Join Us for the Fall Product Launch! Register Now !

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
IFIT
Engaged Sweeper III

I got tired of hunting down and running "Angry IP" every time I wanted to Ping Sweep a subnet, so I put together this command file that can be called from an assets screen. It uses the Windows CMD environment to Ping Sweep the subnet that the asset is on. It writes all found IPs to C:\PingSweep.txt, then opens the file when it is finished. While performing the ping sweep, it echos the IP addresses being pinged to the screen so you can watch its progression.

FIRST: create a command file named PingSweep.cmd and add the following lines to it, (I am attaching this file as well)

@ECHO OFF
CLS
REM Call this command file passing the full IP Address of a network device,
REM i.e. Pingsweep 192.168.1.1
REM Set the Variable "IP" to the IP range passed to the CMD file. This needs to be done
REM because parsing the sub-net from the passed variable does not work.
REM *************************************************************************************************

Set IP=%1

REM Parse the subnet to the "NewIP" variable.
REM this takes each class range of the IP address using the "." as the delimiter
REM and assigns it to the String "NewIP" and adds the necessary "." back in
REM so that the subnet is recreated properly regardless of the subnet IP structure.
REM This does however assume you are pinging a class C network.
REM *************************************************************************************************

FOR /F "tokens=1,2,3* delims=." %%a in ("%IP%") do set NewIP=%%a.%%b.%%c.

REM Echo the Subnet being scanned, and pause to allow continuation or cancel of the PingSweep command.
REM *************************************************************************************************

ECHO The SubNet being scanned is: %NewIP%

REM Give the choice to continue the PingSweep or exit
REM *************************************************************************************************

:menu
CHOICE /C YN /M "Do you wish to Ping Sweep this network?"
IF ERRORLEVEL 2 GOTO Exit
IF ERRORLEVEL 1 GOTO PingIt

REM If not the right subnet, then exit

:Exit
exit


:PingIt
REM Ping the subnet from "0" to "255" showing only those devices who "Reply"
REM the "0" and "255" will return the providers IP address. You can use whois.arin.net to
REM find the service provider. For example 63.232.116.198 returns
REM Quest Communications Company
REM *************************************************************************************************

CLS
ECHO The first and last IP's returned reflect the Internet Providers address. >C:\PingSweep.txt
ECHO You can use whois.arin.net to find the service provider. >> C:\PingSweep.txt
ECHO For example 63.232.116.198 returns Quest Communications Company >> C:\PingSweep.txt
ECHO ************************************************************************** >> C:\PingSweep.txt
ECHO : >> C:\PingSweep.txt
ECHO PLEASE WAIT WHILE THE C:\PINGSWEEP.TXT FILE IS BEING CREATED
ECHO IT WILL BE AUTOMATICALLY OPENED WHEN THE SWEEP IS FINISHED
ECHO *************************************************************

FOR /l %%i in (0,1,255) do @ping %NewIP%%%i -n 1 -w 100 | find "Reply" >> C:\PingSweep.txt | ECHO %NewIP%%%i

START Notepad.exe "C:\PingSweep.txt"


============================================================================================================
SECOND: Save this file into the Lansweeper "Actions" folder.

Create a new action called PingSweep and add this Action:

{actionpath}PingSweep.cmd {ipaddress}

===========================================================================================================

6 REPLIES 6
c_robertson
Engaged Sweeper
I'm trying to create search for active IP addresses and maybe resolve the computer names to put in my sweet of net utilities.

I used part of your batch command.
FOR /l %%i in (0,1,255) do ping %NewIP%%%i -n 1 -w 100 | find "Reply"
I don't need it to go to a text file, just on the screen.
Lets only display the IP address that are active
resolve the name.

either use the gateway for the starting address
echo My Gateway: %gw%
for /f %%a in ('powershell Invoke-RestMethod api.ipify.org') do set PublicIP=%%a
echo Public IP: %PublicIP%
=========================
Or my IP address
for /f "tokens=1-2 delims=:" %%a in ('ipconfig^|find "IPv4"') do set ip=%%b
set ip=%ip:~1%
echo My IP: %ip%
===========================
for nslookup 192.168.0.99 find Name:

IFIT
Engaged Sweeper III
Yep, I'm not sure how new that is though, as I only noticed it for the first time earlier today. I like that it does a quick show of which assets are alive at that time. I'll tell you, that came in handy today. However, it really won't show any rouge machines on the network though, as it is only pings the known assets, so that might be a good reason to use the Ping Sweep. Also, Ping Sweep saves the Ping Replies to a text file and opens it up for easy review and/or uploading to the program of your choice, like, say, Excel.
iboyd
Engaged Sweeper III
I have a "Ping Assets" on the left hand side of my screen under report options. Is that not the case for you?
SolusMIB
Engaged Sweeper II
Thank you for your response!!
That setting makes it possible to see the data you are pulling from with the FIND "REPLY" statement. Definitely adds all the data into the file but we lose the line by line listing that makes it easy to pull into excel.
It's really not a big deal at all and again THANK YOU for posting this action. I'm stoked that I don't have fire up "angry" anymore to do a quick sweep also.

IFIT
Engaged Sweeper III
Sure, Just change this line:
FOR /l %%i in (0,1,255) do @ping %NewIP%%%i -n 1 -w 100 | find "Reply" >> C:\PingSweep.txt | ECHO %NewIP%%%i
to:
FOR /l %%i in (0,1,255) do @ping %NewIP%%%i -n 1 -w 100 >> C:\PingSweep.txt | ECHO %NewIP%%%i
by removing this part:
| find "Reply"

This will echo all results into the text file. The results will look like this:
Pinging 192.168.63.1 with 32 bytes of data:
Reply from 192.168.63.1: bytes=32 time=14ms TTL=251

Ping statistics for 192.168.63.1:
Packets: Sent = 1, Received = 1, Lost = 0 (0% loss),
Approximate round trip times in milli-seconds:
Minimum = 14ms, Maximum = 14ms, Average = 14ms

Pinging 192.168.63.2 with 32 bytes of data:
Request timed out.

Ping statistics for 192.168.63.2:
Packets: Sent = 1, Received = 0, Lost = 1 (100% loss),

I hope this works for you.
SolusMIB
Engaged Sweeper II
Very cool action! Thank you for posting it. I made a few tweeks for myself to make it easier to pull into an excel page and so it deletes the previous file.

Nonetheless, the absolute only thing I would want to see with this is a listing of all the IPs. Is that possible?

New to Lansweeper?

Try Lansweeper For Free

Experience Lansweeper with your own data.
Sign up now for a 14-day free trial.

Try Now