Guest vhuysj Posted March 5, 2005 Share Posted March 5, 2005 Hi I am looking for a script to do the following: Typing in any ip range e.g. 172.28.0.1-255 and the command i need to execute must be looping till all the ip's in the range is done Thanks in advance Johan Link to comment Share on other sites More sharing options...
layer Posted March 5, 2005 Share Posted March 5, 2005 well, this may be what your looking for... Saunders wrote this script, so all credit goes to him expandcollapse popup; Written by Rob Saunders http://rks.no-ip.com #include <GuiConstants.au3> Global Const $LVM_DELETEALLITEMS = 0x1000+9 Global Const $LVM_SETCOLUMNWIDTH = 0x1000+30 Global $sty_Centered = BitOr($SS_CENTERIMAGE, $SS_CENTER) Global $sty_RightNum = BitOr($ES_RIGHT, $ES_NUMBER) GuiCreate('Mass Ping', 340, 270) $s_DefIP = @IPAddress1 $a_DefStartIP = StringSplit($s_DefIP, '.') $s_AddIP = _Long2IP(_IP2Long($s_DefIP) + 4) $a_DefEndIP = StringSplit($s_AddIP, '.') GuiCtrlCreateLabel('&Starting IP Address:', 5, 5, 100, 20, $SS_CENTERIMAGE) $in_StartIP1 = GuiCtrlCreateInput($a_DefStartIP[1], 105, 5, 25, 20, $sty_RightNum) GuiCtrlSetLimit(-1, 3) GuiCtrlCreateLabel('.', 130, 5, 5, 20, $sty_Centered) $in_StartIP2 = GuiCtrlCreateInput($a_DefStartIP[2], 135, 5, 25, 20, $sty_RightNum) GuiCtrlSetLimit(-1, 3) GuiCtrlCreateLabel('.', 160, 5, 5, 20, $sty_Centered) $in_StartIP3 = GuiCtrlCreateInput($a_DefStartIP[3], 165, 5, 25, 20, $sty_RightNum) GuiCtrlSetLimit(-1, 3) GuiCtrlCreateLabel('.', 190, 5, 5, 20, $sty_Centered) $in_StartIP4 = GuiCtrlCreateInput($a_DefStartIP[4], 195, 5, 25, 20, $sty_RightNum) GuiCtrlSetLimit(-1, 3) GuiCtrlCreateLabel('&Ending IP Address:', 5, 25, 100, 20, $SS_CENTERIMAGE) $in_EndIP1 = GuiCtrlCreateInput($a_DefEndIP[1], 105, 25, 25, 20, $sty_RightNum) GuiCtrlSetLimit(-1, 3) GuiCtrlCreateLabel('.', 130, 25, 5, 20, $sty_Centered) $in_EndIP2 = GuiCtrlCreateInput($a_DefEndIP[2], 135, 25, 25, 20, $sty_RightNum) GuiCtrlSetLimit(-1, 3) GuiCtrlCreateLabel('.', 160, 25, 5, 20, $sty_Centered) $in_EndIP3 = GuiCtrlCreateInput($a_DefEndIP[3], 165, 25, 25, 20, $sty_RightNum) GuiCtrlSetLimit(-1, 3) GuiCtrlCreateLabel('.', 190, 25, 5, 20, $sty_Centered) $in_EndIP4 = GuiCtrlCreateInput($a_DefEndIP[4], 195, 25, 25, 20, $sty_RightNum) GuiCtrlSetLimit(-1, 3) GuiCtrlCreateLabel('', 226, 5, 2, 40, $SS_SUNKEN) GuiCtrlCreateLabel('&Timeout:', 235, 5, 50, 20, $SS_CENTERIMAGE) $in_Timeout = GuiCtrlCreateInput('250', 285, 5, 30, 20, $sty_RightNum) GuiCtrlSetLimit(-1, 3) GuiCtrlCreateLabel('ms', 315, 5, 20, 20, $sty_Centered) $bt_Check = GuiCtrlCreateButton('Start &Checking', 235, 25, 100, 20) GuiCtrlSetState(-1, $GUI_DEFBUTTON) $lv_Status = GuiCtrlCreateListView('Address|Status|Ping Time', 5, 50, 330, 200) GuiCtrlSendMsg(-1, $LVM_SETCOLUMNWIDTH, 0, 330 / 3 - 2) GuiCtrlSendMsg(-1, $LVM_SETCOLUMNWIDTH, 1, 330 / 3 - 2) GuiCtrlSendMsg(-1, $LVM_SETCOLUMNWIDTH, 2, 330 / 3 - 2) $lb_StatusBar = GuiCtrlCreateLabel('', 0, 255, 340, 15, BitOr($sty_Centered, $SS_SUNKEN)) GuiSetState() While 1 $i_Msg = GuiGetMsg() Select Case $i_Msg = $bt_Check _CheckAddresses() Case $i_Msg = $GUI_EVENT_CLOSE ExitLoop EndSelect WEnd Func _CheckAddresses() Local $i_SuccessCount = 0, $i_FailCount = 0 GuiCtrlSetState($bt_Check, $GUI_DISABLE) $s_StartIP = GuiCtrlRead($in_StartIP1) & '.' & GuiCtrlRead($in_StartIP2) & '.' & GuiCtrlRead($in_StartIP3) & '.' & GuiCtrlRead($in_StartIP4) $s_EndIP = GuiCtrlRead($in_EndIP1) & '.' & GuiCtrlRead($in_EndIP2) & '.' & GuiCtrlRead($in_EndIP3) & '.' & GuiCtrlRead($in_EndIP4) $i_StartIP = _IP2Long($s_StartIP) $i_EndIP = _IP2Long($s_EndIP) $i_Step = 1 If $i_StartIP - $i_EndIP > 0 Then $i_Step = -1 EndIf GuiCtrlSendMsg($lv_Status, $LVM_DELETEALLITEMS, 0, 0) For $i = $i_StartIP To $i_EndIP Step $i_Step $s_IPAddress = _Long2IP($i) $i_Ping = Ping($s_IPAddress, $in_Timeout) If $i_Ping Then Global $listviewitem = GuiCtrlCreateListViewItem($s_IPAddress & '|Success|' & $i_Ping, $lv_Status) $i_SuccessCount = $i_SuccessCount + 1 Else Select Case @error = 1 $s_Status = 'Host Offline' Case @error = 2 $s_Status = 'Host Unreachable' Case @error = 3 $s_Status = 'Bad destination' Case @error = 4 $s_Status = 'Unknown error' EndSelect GuiCtrlCreateListViewItem($s_IPAddress & '|' & $s_Status & '|-', $lv_Status) $i_FailCount = $i_FailCount + 1 EndIf Next GuiCtrlSetData($lb_StatusBar, $i_SuccessCount & ' successful, ' & $i_FailCount & ' failed') GuiCtrlSetState($bt_Check, $GUI_ENABLE) EndFunc Func _IP2Long($s_IP) Local $i_IP Local $a_IP = StringSplit($s_IP, '.') If $a_IP[0] <> 4 Then SetError(1) Return 0 EndIf $i_IP = Int($a_IP[1]) * 256 ^ 3 +_ Int($a_IP[2]) * 256 ^ 2 +_ Int($a_IP[3]) * 256 +_ Int($a_IP[4]) Return $i_IP EndFunc Func _Long2IP($i_IP) Local $i_IP1, $i_IP2, $i_IP3, $i_IP4 Local $s_IP $i_IP1 = Int($i_IP / 256 ^ 3) $i_IP = Mod($i_IP, 256 ^ 3) $i_IP2 = Int($i_IP / 256 ^ 2) $i_IP = Mod($i_IP, 256 ^ 2) $i_IP3 = Int($i_IP / 256) $i_IP4 = Mod($i_IP, 256) Return $i_IP1 & '.' & $i_IP2 & '.' & $i_IP3 & '.' & $i_IP4 EndFunc FootbaG Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now