AutoIt Forums: nping - Console network pinger / network sweeper / network scanner - AutoIt Forums

Jump to content

Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

nping - Console network pinger / network sweeper / network scanner 192.168.0.1-255 will ping all devices in your network Rate Topic: ***** 1 Votes

#1 User is offline   Manadar 

  • Wikitastic!
  • Icon
  • Group: AutoIt MVPs(MVP)
  • Posts: 8,756
  • Joined: 08-February 06
  • Gender:Male
  • Location:Alkmaar, The Netherlands

Posted 11 January 2010 - 11:48 AM

nping.exe is a console line portable application that scans a network based on a supplied network address from any Windows machine. It is designed for system administrators and other people who are inclined to have need for a simple network scanner. This is finished and complete software.

Output:
[ code='text' ]    ( ExpandCollapse - Popup )
Microsoft Windows [Version 6.1.7600] Copyright (c) 2009 Microsoft Corporation.  All rights reserved. C:\Users\Jos>nping nping.exe scans a network based on a supplied network address. Usage: nping.exe [ipaddress] [local 1-4] [listlocal] Examples:  nping.exe 192.168.0.0-1      will ping these addresses: 192.168.0.0 and 192.168.0.1  nping.exe 192.168.20.*      will ping everything in the range from 192.168.20.1 to 192.168.20.255  nping listlocal      gives you a list of local ipaddresses recognized by the program  nping local      pings your local network, if your ip addresses is 10.0.5.100 then it will p ing everything in 10.0.5.* C:\Users\Jos>nping 74.125.79.* Pinging 255 addresses in range of 74.125.79.* 74.125.79.4 has a roundtrip of 17 ms 74.125.79.5 has a roundtrip of 18 ms 74.125.79.6 has a roundtrip of 22 ms 74.125.79.18 has a roundtrip of 15 ms 74.125.79.27 has a roundtrip of 15 ms 74.125.79.32 has a roundtrip of 17 ms 74.125.79.47 has a roundtrip of 16 ms 74.125.79.52 has a roundtrip of 15 ms 74.125.79.53 has a roundtrip of 16 ms 74.125.79.54 has a roundtrip of 16 ms 74.125.79.57 has a roundtrip of 19 ms 74.125.79.58 has a roundtrip of 16 ms 74.125.79.77 has a roundtrip of 15 ms 74.125.79.79 has a roundtrip of 17 ms 74.125.79.81 has a roundtrip of 15 ms 74.125.79.82 has a roundtrip of 19 ms 74.125.79.84 has a roundtrip of 13 ms 74.125.79.85 has a roundtrip of 18 ms 74.125.79.86 has a roundtrip of 26 ms 74.125.79.91 has a roundtrip of 22 ms 74.125.79.111 has a roundtrip of 14 ms 74.125.79.114 has a roundtrip of 17 ms 74.125.79.116 has a roundtrip of 19 ms 74.125.79.118 has a roundtrip of 22 ms 74.125.79.142 has a roundtrip of 22 ms 74.125.79.143 has a roundtrip of 23 ms 74.125.79.147 has a roundtrip of 20 ms 74.125.79.149 has a roundtrip of 24 ms 74.125.79.161 has a roundtrip of 21 ms 74.125.79.166 has a roundtrip of 17 ms 74.125.79.184 has a roundtrip of 15 ms 74.125.79.206 has a roundtrip of 24 ms 74.125.79.222 has a roundtrip of 16 ms 74.125.79.223 has a roundtrip of 16 ms 74.125.79.224 has a roundtrip of 16 ms 74.125.79.225 has a roundtrip of 17 ms 74.125.79.226 has a roundtrip of 17 ms 74.125.79.231 has a roundtrip of 21 ms 74.125.79.237 has a roundtrip of 22 ms 74.125.79.230 has a roundtrip of 21 ms 74.125.79.250 has a roundtrip of 18 ms 74.125.79.252 has a roundtrip of 16 ms 74.125.79.254 has a roundtrip of 20 ms Ping statistics for 74.125.79.*:         Total hosts pinged:   255         Total hosts UP:       43     [16.86%]         Total hosts DOWN:     212    [83.14%]         Average roundtrip:    18ms C:\Users\Jos>


Tip ! Use the following command to write the results to a text file, you can then use a batch / AutoIt or VBS script to email you the results:
[ code='text' ]    ( Popup )
nping 192.168.20.0-100 > networklog.txt

It will place the results in a file called networklog.txt

Code:
[ autoIt ]    ( ExpandCollapse - Popup )
#NoTrayIcon #Region ;**** Directives created by AutoIt3Wrapper_GUI **** #AutoIt3Wrapper_icon=C:\Windows\Installer\{B924C008-D667-3B26-84C6-BD70285F9BFC}\Icon_app.ico #AutoIt3Wrapper_outfile=nping.exe #AutoIt3Wrapper_Compression=4 #AutoIt3Wrapper_Change2CUI=y #EndRegion ;**** Directives created by AutoIt3Wrapper_GUI **** #include <Constants.au3> #include <Array.au3> Global Const $MAX_PROCESS = 25 ; A maximum number of processes Global Const $MAX_HOSTS = 16777216 ; A maximum number of hosts to ping due to AutoIt's array limit size, and yes, I can work around it but no, I won't Local $networkRange = "" Local $showLocal = False Local $numOfLocalIp = 1 If @Compiled Then     If $CmdLine[0] > 0 Then         For $n = 1 to UBound($CmdLine)-1             Switch $CmdLine[$n]                 Case "/?", "?", "/help", "/info"                     _showHelp()                     Exit 0                 case "listlocal", "locallist"                     ConsoleWrite("Local IP addresses known to this machine: " & @CRLF)                     ConsoleWrite("1: " & @IPAddress1 & @CRLF)                     ConsoleWrite("2: " & @IPAddress2 & @CRLF)                     ConsoleWrite("3: " & @IPAddress3 & @CRLF)                     ConsoleWrite("4: " & @IPAddress4 & @CRLF)                     ConsoleWrite(@CRLF)                     ConsoleWrite("Use: nping local # to ping all devices on these networks")                     Exit 0                 case "local"                     $showLocal = True                     $n +=1                     If $n < UBound($CmdLine) Then                         If $CmdLine[$n] = Number($CmdLine[$n]) Then                             $numOfLocalIp = Number($CmdLine[$n])                             If $numOfLocalIp < 1 Or $numOfLocalIp > 4 Then                                 ConsoleWrite("Local IP address index number must be between 1 and 4" & @CRLF)                                 Exit 0                             EndIf                         EndIf                     EndIf                 Case Else                     $networkRange = $CmdLine[1]             EndSwitch         Next     Else         _showHelp()         Exit 0     EndIf EndIf If $showLocal Then     $localIp = Execute("@IpAddress" & $numOfLocalIp)     $ipParts = StringSplit($localIp, ".")     $networkRange = $ipParts[1] & "." & $ipParts[2] & "." & $ipParts[3] & ".*" EndIf Local $tStart = TimerInit() $aArray = _GetIpAddressList($networkRange) If @error = 1 Then     ConsoleWrite("There are no addresses to be scanned in this range. Check the syntax of your network range." & @CRLF & @CRLF)     _showHelp()     Exit 1 EndIf If @error = 2 Then     ConsoleWrite("Maximum number of hosts to ping is " & $MAX_HOSTS & ", but you tried to ping " & @extended & " hosts" & @CRLF & @CRLF)     _showHelp()     Exit 1 EndIf Local $iTotal = UBound($aArray) If $iTotal = 1 Then     ConsoleWrite("Pinging " & $iTotal & " address in range of " & $networkRange & @CRLF) Else     ConsoleWrite("Pinging " & $iTotal & " addresses in range of " & $networkRange & @CRLF) EndIf ConsoleWrite(@CRLF) Local $aProcess[$MAX_PROCESS] ; An array to keep a reference to spawned processes, in the next loop we fill it with value 0 for reference For $i = 0 To UBound($aProcess) - 1     $aProcess[$i] = 0 Next Local $i = 0 ; which IP are we currently trying to ping ( based on array ) Local $iFinished = 0 ; how many processes have finished pinging Local $iUp = 0 ; Total hosts that are UP Local $iDown = 0 ; Total hosts that are DOWN Local $iTotalRoundTrip = 0 ; Total roundtrip (all the +ms added together) While 1     ; We check all the currently running processes     For $n = 0 To UBound($aProcess) - 1          ; Check if we need a spot, and there is an existing spot here         If ($i <> UBound($aArray) And $aProcess[$n] == 0) Then             $aProcess[$n] = _MSPing($aArray[$i]) ; Spawn a new process in the available spot             $i += 1 ; Increment $i so we can do the next process the next time around         Else             ; Check if this process has been spawned and the process is ready             If ($aProcess[$n] <> 0 And _MSPingIsReady($aProcess[$n])) Then                 ; Get results from the command                 $sHostname = _MSPingGetHostname($aProcess[$n])                 $sResult = _MSPingGetResult($aProcess[$n])                 If ($sResult <> -1) Then ; Check if the host is up                     ConsoleWrite($sHostname & " has a roundtrip of " & $sResult & " ms" & @CRLF)                     $iUp += 1                     $iTotalRoundTrip += $sResult                 Else                     $iDown += 1                 EndIf                 ; Free up an empty space for the next address to Ping                 $aProcess[$n] = 0                 ; Increment the total of processes that have finished                 $iFinished += 1                 ; If the total number of finished processes                 If ($iFinished == UBound($aArray)) Then ExitLoop 2 ; Return             EndIf         EndIf     Next     Sleep(50) ; Give existing ping commands some time to process the request WEnd If $iUp = 0 Then     ConsoleWrite("No devices replied to the ping in this range" & @CRLF)     Exit 0 EndIf Local $percentageUp = Round($iUp / $iTotal * 100, 2) Local $percentageDown = 100-$percentageUp Local $tTotal = TimerDiff($tStart) Local $averageRoundTrip = Round($iTotalRoundTrip / $iUp) Local $sUpPad = "" Local $sDownPad = "" For $i = 0 To 6 - StringLen(String($iUp))     $sUpPad &= " " Next For $i = 0 To 6 - StringLen(String($iDown))     $sDownPad &= " " Next ConsoleWrite(@CRLF) ConsoleWrite("Ping statistics for " & $networkRange & ":" & @CRLF) ConsoleWrite(@TAB & "Total hosts pinged:   " & $iTotal & @CRLF) ConsoleWrite(@TAB & "Total hosts UP:       " & $iUp & $sUpPad & "[" & $percentageUp & "%]" & @CRLF) ConsoleWrite(@TAB & "Total hosts DOWN:     " & $iDown & $sDownPad & "[" & $percentageDown & "%]" & @CRLF) ConsoleWrite(@TAB & "Average roundtrip:    " & $averageRoundTrip  & "ms" & @CRLF) Func _showHelp()     ConsoleWrite("nping.exe scans a network based on a supplied network address." & @CRLF & @CRLF & _     "Usage: nping.exe [ipaddress] [local 1-4] [listlocal]" & @CRLF & @CRLF & _     "Examples: " & @CRLF & " nping.exe 192.168.0.0-1" & @CRLF & "     will ping these addresses: 192.168.0.0 and 192.168.0.1" & @CRLF & _     " nping.exe 192.168.20.*" & @CRLF & "     will ping everything in the range from 192.168.20.1 to 192.168.20.255" & @CRLF & _     " nping listlocal" & @CRLF & "     gives you a list of local ipaddresses recognized by the program" & @CRLF & _     " nping local" & @CRLF & "     pings your local network, if your ip addresses is 10.0.5.100 then it will ping everything in 10.0.5.*" & @CRLF) EndFunc Func _GetIpAddressList($ipFormat)     If $ipFormat = "" Then         Return SetError(1)     EndIf     $ipFormat = StringReplace($ipFormat, "*", "1-255")     $ipSplit = StringSplit($ipFormat, ".")     If $ipSplit[0] <> 4 Then         TCPStartup()         Local $ret[1] = [TCPNameToIP($ipFormat)]         If @error Then Return SetError(1)         Return $ret     EndIf     For $i = 1 To 4         If Not StringRegExp($ipSplit[$i], "[0-9\-]*") Then             TCPStartup()             Local $ret[1] = [TCPNameToIP($ipFormat)]             If @error Then Return SetError(1)             Return $ret         EndIf     Next     Local $ipRange[4][2], $totalPermu = 1     For $i = 0 To 3         If StringInStr($ipSplit[$i + 1], "-") Then             $m = StringSplit($ipSplit[$i + 1], "-")             $ipRange[$i][0] = $m[1]             $ipRange[$i][1] = $m[2]         Else             $n = Number($ipSplit[$i + 1])             $ipRange[$i][0] = $n             $ipRange[$i][1] = $n         EndIf         $totalPermu *= $ipRange[$i][1] - $ipRange[$i][0] + 1     Next     If $totalPermu > $MAX_HOSTS Then         Return SetError(2, String($totalPermu))     EndIf     Local $result[$totalPermu], $i = 0     For $a = $ipRange[0][0] To $ipRange[0][1]         For $b = $ipRange[1][0] To $ipRange[1][1]             For $c = $ipRange[2][0] To $ipRange[2][1]                 For $d = $ipRange[3][0] To $ipRange[3][1]                     $result[$i] = $a & "." & $b & "." & $c & "." & $d                     $i += 1                 Next             Next         Next     Next     Return $result EndFunc   ;==>_GetIpAddressList Func _Exit()     Exit EndFunc   ;==>_Exit Func _MSPing($sHostname, $timeout = 50)     Local $return_struc[4]     ; [0] = Result (in ms)     ; [1] = The hostname originally used     ; [2] = Process handle (for internal use only)     ; [3] = Buffer (for internal use only)     $return_struc[1] = $sHostname     $return_struc[2] = Run("ping " & $sHostname & " -n 1 -w " & $timeout, "", @SW_HIDE, $STDOUT_CHILD)     Return $return_struc EndFunc   ;==>_MSPing Func _MSPingIsReady(ByRef $return_struc)     Return ___MSPingReadOutput($return_struc) EndFunc   ;==>_MSPingIsReady Func _MSPingGetResult($return_struc)     Return $return_struc[0] EndFunc   ;==>_MSPingGetResult Func _MSPingGetHostname($return_struc)     Return $return_struc[1] EndFunc   ;==>_MSPingGetHostname ; Internal use only Func ___MSPingReadOutput(ByRef $return_struc)     $data = StdoutRead($return_struc[2])     If (@error) Then         ___MSPingParseResult($return_struc)         Return 1     Else         $return_struc[3] &= $data         Return 0     EndIf EndFunc   ;==>___MSPingReadOutput ; Internal use only Func ___MSPingParseResult(ByRef $return_struc)     $result = StringRegExp($return_struc[3], "([0-9]*)ms", 3)     If @error Then         $return_struc[0] = -1     Else         $return_struc[0] = $result[0]     EndIf EndFunc   ;==>___MSPingParseResult  


Old version downloads: 180

Download:

Attached File(s)

  • Attached File  nping.exe (291.38K)
    Number of downloads: 100

This post has been edited by Manadar: 17 June 2010 - 04:15 PM


#2 User is offline   Skrip 

  • (Previously known as Firestorm)
  • PipPipPipPipPipPipPip
  • Group: Full Members
  • Posts: 2,281
  • Joined: 26-November 05
  • Gender:Male
  • Location:Look behind you...

Posted 13 January 2010 - 01:31 AM

Very nice! Saved me some time!

Thanks alot.

Although with nping.exe 0-255.0-255.0-255.0-255 it returns

http://img697.imageshack.us/img697/9140/54598496.png

Ran it from the source and it returned

Quote

A:\\\test2.au3 (125) : ==> Array variable subscript badly formatted.:
Local $result[$totalPermu], $i = 0
Local $result[^ ERROR

This post has been edited by Skrip: 13 January 2010 - 01:39 AM


#3 User is offline   Manadar 

  • Wikitastic!
  • Icon
  • Group: AutoIt MVPs(MVP)
  • Posts: 8,756
  • Joined: 08-February 06
  • Gender:Male
  • Location:Alkmaar, The Netherlands

Posted 13 January 2010 - 08:54 AM

It works for all practical purposes. I'm not sure if more error checking is helpful at this point.

Thanks for saying you like it.

This post has been edited by Manadar: 13 January 2010 - 08:54 AM


#4 User is online   czardas 

  • Another Brick In The Wall
  • PipPipPipPipPip
  • Group: Full Members
  • Posts: 881
  • Joined: 14-September 06
  • Gender:Male
  • Location:England

Posted 13 January 2010 - 09:55 AM

It took me a while to figure this out, but I found it quite interesting. I have learned something about using command prompt as well as some new AutoIt syntax. Thanks Manadar. Much appreciated.

This post has been edited by czardas: 13 January 2010 - 09:56 AM


#5 User is offline   nugame 

  • Member
  • Pip
  • Group: Full Members
  • Posts: 63
  • Joined: 07-June 06
  • Location:North Coast Oregon

Posted 13 January 2010 - 05:31 PM

using this for my automation support. thanks.

#6 User is offline   Manadar 

  • Wikitastic!
  • Icon
  • Group: AutoIt MVPs(MVP)
  • Posts: 8,756
  • Joined: 08-February 06
  • Gender:Male
  • Location:Alkmaar, The Netherlands

Posted 17 June 2010 - 04:19 PM

Second version released

Changelog:

Added:
- "local" parameter, you can use nping local to ping your local network. With a number parameter between 1 and 4 you can use @IpAddress2, 3 and 4 instead of the default @IpAddress1
- "listlocal" parameter, will list all the known local networks (@IpAddress#)
- More information to user before starting on what nping will do
- Statistics after ping job giving a #total, #up and #down devices with percentage (%up, %down) and average roundtrip

Fixed:
- Crash when pinging too many devices, it will now error and quit (Thanks Skrip)

#7 User is offline   Zibit 

  • Advanced Member
  • PipPip
  • Group: Full Members
  • Posts: 191
  • Joined: 14-April 09

Posted 17 June 2010 - 06:30 PM

i got a similar one... its in URL Spider

Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

1 User(s) are reading this topic
0 members, 1 guests, 0 anonymous users