This is a simple pair of scripts which will have "threaded" IP scanning. The first script calls the second script in a loop. The second script will return the IP, average latency, and hostname (if resolved). It even has basic subnet functionality.
Code: Select all
#SingleInstance Force
SetWorkingDir %A_ScriptDir%
TestFile = IPScanLog.csv
filedelete %TempFile%
Gui, Add, Text,,Please enter starting IP address
Gui, Add, Edit, w40 number limit3 vOct1
Gui, Add, Text,x+,*
Gui, Add, Edit, w40 x+ number limit3 vOct2
Gui, Add, Text,x+,*
Gui, Add, Edit, w40 x+ number limit3 vOct3
Gui, Add, Text,x+,*
Gui, Add, Edit, w40 x+ number limit3 vOct4
Gui, Add, Text,y+10 x9,Scan how many IPs?`n(`/subnet)
Gui, Add, Edit, w40 x+ vHowMany
Gui, Add, Text, y+10 x9,Ping#
Gui, Add, Edit, W20 x+ number limit2 vPingNumber,4
Gui, Add, Text, x+,Timeout
Gui, Add, Edit, W40 x+ number limit4 vTimeout,1000
Gui, Add, Button, x+5 r1,Scan range
Gui, Color, Gray
Gui, Add, Statusbar
SB_SetParts(85,60)
SB_SetText("`t"A_IPAddress1,1)
SB_SetText("`t"A_ComputerName,2)
SB_SetText("`t"A_UserName,3)
Gui, Color, Gray
Gui Show,,IP Scanner
Return
buttonScanRange:
gui, submit,nohide
StartIP = %Oct1%.%Oct2%.%Oct3%.%Oct4%
if instr(HowMany,"/")
{
Howmany := SubStr(HowMany,2)
HowMany := 32 - HowMany
HowMany := 2**howmany
}
FinalRange := Oct4 + HowMany
if ( ( PingNumber = "") || ( PingNumber = "0" ) )
{
PingNumber = 1
}
if ( Timeout = "" )
{
Timeout = 50
}
if ( Timeout <= 50 )
{
Timeout = 50
}
loop %HowMany%
{
IPAddress = %Oct1%.%Oct2%.%Oct3%.%Oct4%
run Threaded.AHK %IPAddress% %PingNumber% %TimeOut%
Oct4++
If Oct4 > 255
{
Oct4 = 0
Oct3++
}
If Oct3 > 255
{
Oct3 = 0
Oct2++
}
If Oct2 > 255
{
Oct2 = 0
Oct1++
}
sleep 250
}
msgbox Done
Return
guiclose:
exitapp
Escape::ExitApp
Code: Select all
SetWorkingDir %A_ScriptDir%
#NoTrayIcon
IP = %1%
PingNumber = %2%
TimeOut = %3%
TempFile = %IP%.temp
Temp2 = %IP%.temp2
TestFile = IPScanLog.csv
Count = -n %PingNumber%
runwait %comspec% /c ping %IP% %Count% -w %TimeOut% | find "Average" > %Temp2%,,hide
If !Errorlevel
{
runwait %comspec% /c nslookup %ip%| find "Name" > %tempfile%,,hide
loop, read, %tempfile%
if instr(a_loopreadline,"Name")
{
StringReplace,Name,A_LoopReadLine,Name:
Name := trim(Name)
}
if Name =
Name = No Matching Name Found
Loop, read, %Temp2%
if instr(a_loopreadline,"Average")
{
Average := trim(A_loopReadLine)
AvgPos := InStr(Average,"Average")
AvgPos := AvgPos + 9
StringTrimLeft,Average,Average,%AvgPos%
}
FileAppend,%IP%`,%average%`,%Name%`n,%TestFile%
}
FileDelete,%TempFile%
FileDelete,%Temp2%
exitapp
Edit: Added some more functionality. The ability to pick number of pings, timeouts, add a statusbar with useful details (in some situations, could probably loop A_IPAddress%A_Index% to find which ones don't return blank and show that in the status bar. Maybe make the UI a bit cleaner).