#include <inet.au3>
#include <array.au3>
#include <GUIConstantsEx.au3>
#include <ProgressConstants.au3>
GUICreate("Network Scanner", 200, 130)
GUICtrlCreateLabel("IP-Bereich:", 10, 10, 100, 30)
$1 = GUICtrlCreateInput("192", 105, 10, 30, 30)
$2 = GUICtrlCreateInput("168", 140, 10, 30, 30)
$3 = GUICtrlCreateInput("0", 175, 10, 30, 30)
$scan = GUICtrlCreateButton("Scannen", 50, 50, 100, 40)
$progress = GUICtrlCreateProgress(10, 100, 180, 20)
$dll = DllOpen("ws2_32.dll")
GUISetState()
Dim $array[257][2]
$array[0][0] = "IP"
$array[0][1] = "Name"
$i = 0
TCPStartup()
FileDelete(@ScriptDir & "ping.ini")
While 1 * Sleep(10)
$msg = GUIGetMsg()
Switch $msg
Case $scan
_scan()
_show()
Case - 3
Exit
EndSwitch
WEnd
#cs
Func _ScanIPRange($sIP_Range, $iWaitms = 100)
If Not StringRegExp($sIP_Range, '\d{1,3}\.\d{1,3}\.\d{1,3}\.') Then Return SetError(1, 0, 0)
Local $sPID, $sOut, $aOut[1][2], $sTmp
For $i = 1 To 255
$sOut = ''
ToolTip('Scanne IP: ' & $sIP_Range & $i)
$sPID = Run(@ComSpec & ' /c ping -a -w ' & $iWaitms & ' -4 -n 1 ' & $sIP_Range & $i, @SystemDir, @SW_HIDE, $STDOUT_CHILD)
Do
Sleep(10)
$sOut &= StdoutRead($sPID)
Until @error <> 0
If Not StringInStr($sOut, '100% Verlust') Then
$aOut[UBound($aOut) - 1][0] = $sIP_Range & $i
$sTmp = StringRegExpReplace($sOut, '(?s).+Ping (\H+?) .+', '$1')
If $sTmp = 'wird' Then $sTmp = 'Hostname nicht gefunden'
$aOut[UBound($aOut) - 1][1] = $sTmp
ReDim $aOut[UBound($aOut) + 1][2]
EndIf
Next
ReDim $aOut[UBound($aOut) - 1][2]
ToolTip('')
Return $aOut
EndFunc ;==>_ScanIPRange
#ce
Func _scan()
For $i = 0 To 255
$ip = GUICtrlRead($1) & "." & GUICtrlRead($2) & "." & GUICtrlRead($3) & "." & $i
Run("ping.exe " & $ip)
ConsoleWrite($ip & @CRLF)
Next
GUICtrlSetData($progress, 50)
Do
Sleep(100)
Until Not ProcessExists("ping.exe")
$pings = IniReadSection("ping.ini", "pings")
For $i = 1 To UBound($pings) - 1
$subIP = StringReplace($pings[$i][0], GUICtrlRead($1) & "." & GUICtrlRead($2) & "." & GUICtrlRead($3) & ".", "")
ConsoleWrite($subIP & @CRLF)
$array[$subIP + 1][0] = $pings[$i][0]
If Number($pings[$i][1]) <> 0 Then
$array[$subIP + 1][1] = _TCPIpToName($pings[$i][0], 0, $dll)
If $array[$subIP + 1][1] = "" Then
$array[$subIP + 1][1] = "Unnamed Host"
EndIf
Else
$array[$subIP + 1][1] = "Error: (" & $pings[$i][1] & ")"
EndIf
GUICtrlSetData($progress, 50 + (100 / 255 * $i) / 2)
Next
FileDelete(@ScriptDir & "ping.ini")
EndFunc ;==>_scan
Func _show()
_ArrayDisplay($array, "IP´s / Names")
EndFunc ;==>_show
DllClose($dll)