Notification

Icon
Error

Ping Sweep a Subnet - From any asset screen, Ping Sweep the entire subnet that it is on.

Posted: Thursday, November 5, 2015 8:07:17 PM(UTC)
IFIT

IFIT

Member Original PosterPosts: 23
6
Like
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}

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

Handles attachments
PingSweep.txt (3kb) downloaded 387 time(s).
SolusMIB
#1SolusMIB Member Posts: 5  
posted: 12/2/2015 9:22:46 PM(UTC)
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?
IFIT
#2IFIT Member Original PosterPosts: 23  
posted: 12/2/2015 10:15:30 PM(UTC)
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. Angel
SolusMIB
#3SolusMIB Member Posts: 5  
posted: 12/3/2015 3:33:59 PM(UTC)
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.

iboyd
#4iboyd Member Posts: 26  
posted: 12/13/2016 7:13:59 PM(UTC)
I have a "Ping Assets" on the left hand side of my screen under report options. Is that not the case for you?
IFIT
#5IFIT Member Original PosterPosts: 23  
posted: 12/13/2016 7:33:35 PM(UTC)
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.
Computer Doctor
#6Computer Doctor Member Posts: 1  
posted: 12/23/2020 7:16:01 PM(UTC)
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:

Active Discussions

Lansweeper Scan User Exclusion / Define User OU for active scanning
by  Almada   Go to last post Go to first unread
Last post: Yesterday at 6:43:34 PM(UTC)
Lansweeper sqlServerId is changing
by  Ciro Bizelli  
Go to last post Go to first unread
Last post: Yesterday at 3:40:34 PM(UTC)
Lansweeper Slow Loading Lansweeper
by  Maikel Vanroelen   Go to last post Go to first unread
Last post: Yesterday at 9:25:31 AM(UTC)
Lansweeper Sync information
by  Jay-IT  
Go to last post Go to first unread
Last post: 9/16/2021 9:20:11 PM(UTC)
Lansweeper "Unknown" exclusion does not exclude Unknown assets
by  Almada   Go to last post Go to first unread
Last post: 9/16/2021 7:18:43 PM(UTC)
Lansweeper multiple scanning servers with granular permission
by  FrankSc  
Go to last post Go to first unread
Last post: 9/16/2021 6:29:54 PM(UTC)
Lansweeper Separate helpdesk websites?
by  JCochran   Go to last post Go to first unread
Last post: 9/15/2021 2:51:03 PM(UTC)
Lansweeper Remove Ads
by  FrankSc  
Go to last post Go to first unread
Last post: 9/15/2021 12:30:18 PM(UTC)