Check it out below:
#include <file.au3> #include <array.au3> #include <inet.au3> #include <guiconstants.au3> #include <guicombobox.au3> #include <guiconstantsex.au3> #include <buttonconstants.au3> #include <editconstants.au3> #include <windowsconstants.au3> Global $selectedIP, $errorCode = 0, $available, $availableIPOnly, $begin, $end, $errorLabel, $tempIpAddress = "", $count = 0, $outputIP = "", $outputIPOnly, $leftSide If @IPAddress1 <> "0.0.0.0" Then $tempIpAddress = "Adapter #1: " & @IPAddress1 $selectedIP = @IPAddress1 $count = $count + 1 EndIf If @IPAddress2 <> "0.0.0.0" Then $tempIpAddress = $tempIpAddress & "|" & "Adapter #2: " & @IPAddress2 $selectedIP = @IPAddress2 $count = $count + 1 EndIf If @IPAddress3 <> "0.0.0.0" Then $tempIpAddress = $tempIpAddress & "|" & "Adapter #3: " & @IPAddress3 $selectedIP = @IPAddress3 $count = $count + 1 EndIf If @IPAddress4 <> "0.0.0.0" Then $tempIpAddress = $tempIpAddress & "|" & "Adapter #4: " & @IPAddress4 $selectedIP = @IPAddress3 $count = $count + 1 EndIf If $count > 1 Then $initialGUI = GUICreate("Select the IP range", 330, 87) $Label = GUICtrlCreateLabel("What network adapter do you want to use?", 24, 8, 209, 17) $IPCombo = GUICtrlCreateCombo("", 24, 40, 200, 25, BitOR($CBS_DROPDOWNLIST, $CBS_AUTOHSCROLL)) GUICtrlSetData($IPCombo, $tempIpAddress) $Go = GUICtrlCreateButton("Go", 240, 40, 59, 25, 0) GUISetState(@SW_SHOW) While 1 $nMsg = GUIGetMsg() Switch $nMsg Case $GUI_EVENT_CLOSE Exit Case $Go $selectedIP = GUICtrlRead($IPCombo) If $selectedIP = "" Then MsgBox(0, "Error", "You must make a selection from the drop-down list.") Else GUIDelete($initialGUI) ExitLoop Endif EndSwitch WEnd EndIf If StringInStr($selectedIP, @IPAddress1) Then $selectedIP = @IPAddress1 ElseIf StringInStr($selectedIP, @IPAddress2) Then $selectedIP = @IPAddress2 ElseIf StringInStr($selectedIP, @IPAddress3) Then $selectedIP = @IPAddress3 ElseIf StringInStr($selectedIP, @IPAddress3) Then $selectedIP = @IPAddress3 EndIf $ipAddress = StringSplit($selectedIP, ".") $mainGUI = GUICreate("Find Available IP Addresses", 450, 119) $Label1 = GUICtrlCreateLabel("Enter IP Address Range", 16, 8, 170, 20) GUICtrlSetFont(-1, 10, 800, 0, "MS Sans Serif") $Label2 = GUICtrlCreateLabel("From:", 24, 40, 30, 17) $iOct1 = GUICtrlCreateInput($ipAddress[1], 24, 64, 33, 21) GUICtrlSetState($iOct1, $GUI_DISABLE) $iOct2 = GUICtrlCreateInput($ipAddress[2], 64, 64, 33, 21) GUICtrlSetState($iOct2, $GUI_DISABLE) $iOct3 = GUICtrlCreateInput($ipAddress[3], 104, 64, 33, 21) GUICtrlSetState($iOct3, $GUI_DISABLE) $iOct4 = GUICtrlCreateInput("", 144, 64, 33, 21) GUICtrlSetTip($iOct4, "Must be a number between 1 and 253.") GUICtrlSetLimit($iOct4, 3) GUICtrlSetState($iOct4, $GUI_FOCUS) $fLabel = GUICtrlCreateLabel("To:", 216, 40, 20, 17) $fOct4 = GUICtrlCreateInput("", 216, 64, 33, 21) GUICtrlSetTip($fOct4, "Must be a number between 1 and 254.") GUICtrlSetLimit($fOct4, 3) $Button1 = GUICtrlCreateButton("Find Available IP Addresses", 280, 8, 155, 41, 0) $Combo1 = GUICtrlCreateCombo("10", 352, 64, 65, 25, BitOR($CBS_DROPDOWNLIST, $CBS_AUTOHSCROLL)) GUICtrlSetTip($Combo1, "A higher value may (or may not) give more accurate results. But it will run slower.") GUICtrlSetData($Combo1, "10|100|1000|2000|4000|8000") $Label4 = GUICtrlCreateLabel("Timeout [ms]", 280, 64, 64, 17) GUICtrlSetTip($Label4, "A higher value may (or may not) give more accurate results. But it will run slower.") $Label3 = GUICtrlCreateLabel("-", 193, 60, 12, 23) GUICtrlSetFont(-1, 18, 400, 0, "Arial") $Checkbox1 = GUICtrlCreateCheckbox("Show Unavailable IPs", 280, 92, 120, 17) GUICtrlSetTip($Checkbox1, 'Unavailable IPs will be listed as "This IP address is in use"') $fusionSolid = GUICtrlCreateLabel("www.fusionsolid.com", 22, 98, 150, 17) GUICtrlSetColor($fusionSolid, 0x0033ff) GUICtrlSetCursor ($fusionSolid, 0) GUISetState(@SW_SHOW) While 1 $nMsg = GUIGetMsg() Switch $nMsg Case $GUI_EVENT_CLOSE Exit Case $Button1 _BeginPing() Case $fusionSolid ShellExecute("<a href='http://www.fusionsolid.com' class='bbc_url' title='External link' rel='nofollow external'>http://www.fusionsolid.com"</a>) EndSwitch WEnd Func _BeginPing() $outputIP = "" GUICtrlSetBkColor($iOct4, 0xffffff) GUICtrlSetBkColor($fOct4, 0xffffff) GUICtrlDelete($errorLabel) _ErrorCheck() If $errorCode = 0 Then GUISetState(@SW_DISABLE, $mainGUI) $baseAddress = GUICtrlRead($iOct1) & "." & GUICtrlRead($iOct2) & "." & GUICtrlRead($iOct3) & "." $j = 0 $k = 0 $timeout = GUICtrlRead($Combo1) ProgressOn("Scanning for available IP addresses", "Progress") Dim $available[1], $availableIPOnly[1] $cycle = $end - $begin For $i = $begin To $end Step 1 Ping($baseAddress & $i, $timeout) If @error Then If @error = 1 Then $errorMsg = "Host is offline" ElseIf $errorMsg = 2 Then $errorMsg = "Host is unreachable" ElseIf $errorMsg = 3 Then $errorMsg = "Bad destination" Else $errorMsg = "Other errors" EndIf $available[$j] = $baseAddress & $i & " - " & $errorMsg $availableIPOnly[$j] = $baseAddress & $i $j += 1 ReDim $available[$j + 1] ReDim $availableIPOnly[$j + 1] EndIf If NOT @error AND GUICtrlRead($Checkbox1) = 1 Then $available[$j] = $baseAddress & $i & " - " & "This IP address is in use" $availableIPOnly[$j] = $baseAddress & $i $j += 1 ReDim $available[$j + 1] ReDim $availableIPOnly[$j + 1] EndIf ProgressSet(100 / $cycle * $k) $k += 1 Next ProgressOff() GUISetState($mainGUI, @SW_ENABLE) $arraySize = UBound($available) If $available[$arraySize - 1] = "" Then ReDim $available[$arraySize - 1] EndIf $arraySize = UBound($availableIPOnly) If $availableIPOnly[$arraySize - 1] = "" Then ReDim $availableIPOnly[$arraySize - 1] EndIf GUISetState(@SW_ENABLE, $mainGUI) _OutputWindow() EndIf EndFunc ;==>_BeginPing Func _ErrorCheck() $errorCode = 0 $begin = Number(GUICtrlRead($iOct4)) $end = Number(GUICtrlRead($fOct4)) If $begin < 1 Or $begin > 253 Or IsInt($begin) = 0 Then GUICtrlSetBkColor($iOct4, 0xffff33) $errorLabel = GUICtrlCreateLabel("The highlighted item (starting value) must be a number between 1 and 253", 24, 88, 376, 17) GUICtrlSetColor(-1, 0xFF0000) GUICtrlSetState($iOct4, $GUI_FOCUS) $errorCode = 1 ElseIf $end < 1 Or $end > 254 Or IsInt($end) = 0 Then GUICtrlSetBkColor($fOct4, 0xffff33) $errorLabel = GUICtrlCreateLabel("The highlighted item (ending value) must be a number between 1 and 254", 24, 88, 376, 17) GUICtrlSetColor(-1, 0xFF0000) GUICtrlSetState($fOct4, $GUI_FOCUS) $errorCode = 1 ElseIf $end < $begin Then GUICtrlSetBkColor($iOct4, 0xffffff) GUICtrlSetBkColor($fOct4, 0xffffff) GUICtrlDelete($errorLabel) $errorLabel = GUICtrlCreateLabel("The starting value (From) must be lower than the ending value (To)", 24, 88, 376, 17) GUICtrlSetColor(-1, 0xFF0000) GUICtrlSetState($iOct4, $GUI_FOCUS) GUICtrlSetBkColor($fOct4, 0xffff33) GUICtrlSetBkColor($iOct4, 0xffff33) $errorCode = 1 EndIf EndFunc ;==>_ErrorCheck Func _OutputWindow() For $i = 1 to UBound($available) Step 1 $outputIP = $outputIP & $available[$i - 1] & @CRLF Next $outputWindow = GUICreate("Available IP Addresses", 425, 441, 192, 124) $outputDataWindow = GUICtrlCreateEdit("", 8, 8, 409, 393) GUICtrlSetData($outputDataWindow, $outputIP) $copyIPOnly = GUICtrlCreateButton("Copy IP Addresses Only", 8, 408, 203, 25) $copyIPAndCode = GUICtrlCreateButton("Copy IP Addresses And Codes", 216, 408, 203, 25) GUISetState(@SW_SHOW) While 1 $nMsg = GUIGetMsg() Switch $nMsg Case $GUI_EVENT_CLOSE GUIDelete($outputWindow) ExitLoop Case $copyIPOnly $outputIP = "" For $i = 1 to UBound($available) Step 1 $outputIP = $outputIP & $availableIPOnly[$i - 1] & @CRLF Next ClipPut($outputIP) GUIDelete($outputWindow) ExitLoop Case $copyIPAndCode $outputIP = "" $outputIP = GUICtrlRead($outputDataWindow) ClipPut($outputIP) GUIDelete($outputWindow) ExitLoop EndSwitch WEnd EndFunc
Edit: Changed labels from confusing terms like "Host is offline" to "Available". It makes more sense. Plus, I found a few bugs and fixed them. New code below:
#include <File.au3> #include <Array.au3> #include <INet.au3> #include <GUIConstants.au3> #include <GuiComboBox.au3> #include <GUIConstantsEx.au3> #include <ButtonConstants.au3> #include <EditConstants.au3> #include <WindowsConstants.au3> Global $selectedIP, $errorCode = 0, $available, $availableIPOnly, $begin, $end, $errorLabel, $tempIpAddress = "", $count = 0, $outputIP = "", $outputIPOnly, $leftSide If @IPAddress1 <> "0.0.0.0" Then $tempIpAddress = "Adapter #1: " & @IPAddress1 $selectedIP = @IPAddress1 $count = $count + 1 EndIf If @IPAddress2 <> "0.0.0.0" Then $tempIpAddress = $tempIpAddress & "|" & "Adapter #2: " & @IPAddress2 $selectedIP = @IPAddress2 $count = $count + 1 EndIf If @IPAddress3 <> "0.0.0.0" Then $tempIpAddress = $tempIpAddress & "|" & "Adapter #3: " & @IPAddress3 $selectedIP = @IPAddress3 $count = $count + 1 EndIf If @IPAddress4 <> "0.0.0.0" Then $tempIpAddress = $tempIpAddress & "|" & "Adapter #4: " & @IPAddress4 $selectedIP = @IPAddress3 $count = $count + 1 EndIf If $count > 1 Then $initialGUI = GUICreate("Select the IP range", 330, 87) $Label = GUICtrlCreateLabel("What network adapter do you want to use?", 24, 8, 209, 17) $IPCombo = GUICtrlCreateCombo("", 24, 40, 200, 25, BitOR($CBS_DROPDOWNLIST, $CBS_AUTOHSCROLL)) GUICtrlSetData($IPCombo, $tempIpAddress) $Go = GUICtrlCreateButton("Go", 240, 40, 59, 25, 0) GUISetState(@SW_SHOW) While 1 $nMsg = GUIGetMsg() Switch $nMsg Case $GUI_EVENT_CLOSE Exit Case $Go $selectedIP = GUICtrlRead($IPCombo) If $selectedIP = "" Then MsgBox(0, "Error", "You must make a selection from the drop-down list.") Else GUIDelete($initialGUI) ExitLoop Endif EndSwitch WEnd EndIf If StringInStr($selectedIP, @IPAddress1) Then $selectedIP = @IPAddress1 ElseIf StringInStr($selectedIP, @IPAddress2) Then $selectedIP = @IPAddress2 ElseIf StringInStr($selectedIP, @IPAddress3) Then $selectedIP = @IPAddress3 ElseIf StringInStr($selectedIP, @IPAddress3) Then $selectedIP = @IPAddress3 EndIf $ipAddress = StringSplit($selectedIP, ".") $mainGUI = GUICreate("Available IPs .: www.fusionsolid.com", 450, 130) $Label1 = GUICtrlCreateLabel("Enter IP Address Range", 16, 8, 170, 20) GUICtrlSetFont(-1, 10, 800, 0, "MS Sans Serif") $Label2 = GUICtrlCreateLabel("From:", 24, 40, 30, 17) $iOct1 = GUICtrlCreateInput($ipAddress[1], 24, 64, 33, 21) GUICtrlSetState($iOct1, $GUI_DISABLE) $iOct2 = GUICtrlCreateInput($ipAddress[2], 64, 64, 33, 21) GUICtrlSetState($iOct2, $GUI_DISABLE) $iOct3 = GUICtrlCreateInput($ipAddress[3], 104, 64, 33, 21) GUICtrlSetState($iOct3, $GUI_DISABLE) $iOct4 = GUICtrlCreateInput("", 144, 64, 33, 21) GUICtrlSetTip($iOct4, "Must be a number between 1 and 253.") GUICtrlSetLimit($iOct4, 3) GUICtrlSetState($iOct4, $GUI_FOCUS) $fLabel = GUICtrlCreateLabel("To:", 216, 40, 20, 17) $fOct4 = GUICtrlCreateInput("", 216, 64, 33, 21) GUICtrlSetTip($fOct4, "Must be a number between 1 and 254.") GUICtrlSetLimit($fOct4, 3) $Button1 = GUICtrlCreateButton("Find Available IP Addresses", 280, 8, 155, 41, 0) $Combo1 = GUICtrlCreateCombo("10", 352, 64, 65, 25, BitOR($CBS_DROPDOWNLIST, $CBS_AUTOHSCROLL)) GUICtrlSetTip($Combo1, "A higher value may (or may not) give more accurate results. But it will run slower.") GUICtrlSetData($Combo1, "100|1000|2000|4000|8000", "10") $Label4 = GUICtrlCreateLabel("Timeout [ms]", 280, 64, 64, 17) GUICtrlSetTip($Label4, "A higher value may (or may not) give more accurate results. But it will run slower.") $Label3 = GUICtrlCreateLabel("-", 193, 60, 12, 23) GUICtrlSetFont(-1, 18, 400, 0, "Arial") $Checkbox1 = GUICtrlCreateCheckbox("Show Unavailable IPs", 280, 107, 120, 17) GUICtrlSetTip($Checkbox1, 'Unavailable IPs will be listed as "This IP address is in use"') $fusionSolid = GUICtrlCreateLabel("www.fusionsolid.com", 22, 110, 150, 17) GUICtrlSetColor($fusionSolid, 0x0033ff) GUICtrlSetCursor ($fusionSolid, 0) GUISetState(@SW_SHOW) While 1 $nMsg = GUIGetMsg() Switch $nMsg Case $GUI_EVENT_CLOSE Exit Case $Button1 _BeginPing() Case $fusionSolid ShellExecute("<a href='http://www.fusionsolid.com' class='bbc_url' title='External link' rel='nofollow external'>http://www.fusionsolid.com"</a>) EndSwitch WEnd Func _BeginPing() $outputIP = "" GUICtrlSetBkColor($iOct4, 0xffffff) GUICtrlSetBkColor($fOct4, 0xffffff) GUICtrlDelete($errorLabel) _ErrorCheck() If $errorCode = 0 Then GUISetState(@SW_DISABLE, $mainGUI) $baseAddress = GUICtrlRead($iOct1) & "." & GUICtrlRead($iOct2) & "." & GUICtrlRead($iOct3) & "." $j = 0 $k = 0 $timeout = GUICtrlRead($Combo1) ProgressOn("Scanning for available IP addresses", "Progress") Dim $available[1], $availableIPOnly[1] $cycle = $end - $begin For $i = $begin To $end Step 1 Ping($baseAddress & $i, $timeout) If @error Then If @error = 1 Then $errorMsg = "Available" ElseIf $errorMsg = 2 Then $errorMsg = "Available" ElseIf $errorMsg = 3 Then $errorMsg = "Bad destination" Else $errorMsg = "Misc error reaching destination" EndIf $available[$j] = $baseAddress & $i & " - " & $errorMsg $availableIPOnly[$j] = $baseAddress & $i $j += 1 ReDim $available[$j + 1] ReDim $availableIPOnly[$j + 1] EndIf If NOT @error AND GUICtrlRead($Checkbox1) = 1 Then $available[$j] = $baseAddress & $i & " - " & "This IP address is in use" $availableIPOnly[$j] = $baseAddress & $i $j += 1 ReDim $available[$j + 1] ReDim $availableIPOnly[$j + 1] EndIf ProgressSet(100 / $cycle * $k) $k += 1 Next ProgressOff() GUISetState($mainGUI, @SW_ENABLE) $arraySize = UBound($available) If $available[$arraySize - 1] = "" Then ReDim $available[$arraySize - 1] EndIf $arraySize = UBound($availableIPOnly) If $availableIPOnly[$arraySize - 1] = "" Then ReDim $availableIPOnly[$arraySize - 1] EndIf GUISetState(@SW_ENABLE, $mainGUI) _OutputWindow() EndIf EndFunc ;==>_BeginPing Func _ErrorCheck() $errorCode = 0 $begin = Number(GUICtrlRead($iOct4)) $end = Number(GUICtrlRead($fOct4)) If $begin < 1 Or $begin > 253 Or IsInt($begin) = 0 Then GUICtrlSetBkColor($iOct4, 0xffff33) $errorLabel = GUICtrlCreateLabel("The highlighted item (starting value) must be a number between 1 and 253", 24, 90, 376, 17) GUICtrlSetColor(-1, 0xFF0000) GUICtrlSetState($iOct4, $GUI_FOCUS) $errorCode = 1 ElseIf $end < 1 Or $end > 254 Or IsInt($end) = 0 Then GUICtrlSetBkColor($fOct4, 0xffff33) $errorLabel = GUICtrlCreateLabel("The highlighted item (ending value) must be a number between 1 and 254", 24, 90, 376, 17) GUICtrlSetColor(-1, 0xFF0000) GUICtrlSetState($fOct4, $GUI_FOCUS) $errorCode = 1 ElseIf $end < $begin Then GUICtrlSetBkColor($iOct4, 0xffffff) GUICtrlSetBkColor($fOct4, 0xffffff) GUICtrlDelete($errorLabel) $errorLabel = GUICtrlCreateLabel("The starting value (From) must be lower than the ending value (To)", 24, 90, 376, 17) GUICtrlSetColor(-1, 0xFF0000) GUICtrlSetState($iOct4, $GUI_FOCUS) GUICtrlSetBkColor($fOct4, 0xffff33) GUICtrlSetBkColor($iOct4, 0xffff33) $errorCode = 1 ElseIf $end = $begin Then GUICtrlSetBkColor($iOct4, 0xffffff) GUICtrlSetBkColor($fOct4, 0xffffff) GUICtrlDelete($errorLabel) $errorLabel = GUICtrlCreateLabel("The starting value (From) must be lower than the ending value (To)", 24, 90, 376, 17) GUICtrlSetColor(-1, 0xFF0000) GUICtrlSetState($iOct4, $GUI_FOCUS) GUICtrlSetBkColor($fOct4, 0xffff33) GUICtrlSetBkColor($iOct4, 0xffff33) $errorCode = 1 EndIf EndFunc ;==>_ErrorCheck Func _OutputWindow() GUISetState(@SW_DISABLE, $mainGUI) For $i = 1 to UBound($available) Step 1 $outputIP = $outputIP & $available[$i - 1] & @CRLF Next $outputWindow = GUICreate("Available IP Addresses", 425, 441) $outputDataWindow = GUICtrlCreateEdit("", 8, 8, 409, 393) GUICtrlSetState(-1, $GUI_FOCUS) GUICtrlSetData($outputDataWindow, $outputIP) $copyIPOnly = GUICtrlCreateButton("Copy IP Addresses Only", 8, 408, 203, 25) $copyIPAndCode = GUICtrlCreateButton("Copy IP Addresses And Codes", 216, 408, 203, 25) GUISetState(@SW_SHOW) While 1 $nMsg = GUIGetMsg() Switch $nMsg Case $GUI_EVENT_CLOSE GUISetState(@SW_ENABLE, $mainGUI) GUIDelete($outputWindow) ExitLoop Case $copyIPOnly $outputIP = "" For $i = 1 to UBound($available) Step 1 $outputIP = $outputIP & $availableIPOnly[$i - 1] & @CRLF Next ClipPut($outputIP) GUISetState(@SW_ENABLE, $mainGUI) GUIDelete($outputWindow) ExitLoop Case $copyIPAndCode $outputIP = "" $outputIP = GUICtrlRead($outputDataWindow) ClipPut($outputIP) GUISetState(@SW_ENABLE, $mainGUI) GUIDelete($outputWindow) ExitLoop EndSwitch WEnd EndFunc
Edited by sleepydvdr, 28 January 2012 - 10:18 AM.





