; ---------------------------------------------------------------------------- ; ; AutoIt Version: 3.1.0 ; Author: A.N.Other ; ; Script Function: ; Template AutoIt script. ; ; ---------------------------------------------------------------------------- ; Script Start - Add your code below here #include #region --- GuiBuilder code Start --- ; Script generated by AutoBuilder 0.5 Prototype #include If Not IsDeclared('WS_CLIPSIBLINGS') Then Global $WS_CLIPSIBLINGS = 0x04000000 GuiCreate("MyGUI", 270, 73,(@DesktopWidth-270)/2, (@DesktopHeight-73)/2 , $WS_OVERLAPPEDWINDOW + $WS_VISIBLE + $WS_CLIPSIBLINGS) $Button_1 = GuiCtrlCreateButton("Set to IP Addr:", 20, 10, 90, 20) $Input_2 = GuiCtrlCreateInput("123.456.789.012", 120, 10, 130, 20) $Button_2 = GuiCtrlCreateButton("Reset IP Addr", 20, 40, 90, 20) ;Read IP from ini file $var = IniRead("IPAddr.ini", "IP Settings", "IPAddress", "123.456.789.012") GUICtrlSetData($Input_2,$var) ;Check if alternate IP Address is already set if FileExists("netconf.txt") Then GUICtrlSetState ( $Button_1, $GUI_DISABLE ) GUICtrlSetState ( $Input_2, $GUI_DISABLE ) GUICtrlSetState ( $Button_2, $GUI_ENABLE ) Else GUICtrlSetState ( $Button_1, $GUI_ENABLE ) GUICtrlSetState ( $Input_2, $GUI_ENABLE ) GUICtrlSetState ( $Button_2, $GUI_DISABLE ) EndIf GuiSetState() While 1 $msg = GuiGetMsg() Select Case $msg = $GUI_EVENT_CLOSE ExitLoop Case $msg = $Button_1 _SetIP(GUICtrlRead($Input_2)) ExitLoop Case $msg = $Button_2 _ResetIP() ExitLoop Case Else ;;; EndSelect WEnd ;Write ini file IniWrite ( "IPAddr.ini", "IP Settings", "IPAddress", GUICtrlRead($Input_2) ) Exit #endregion --- GuiBuilder generated code End --- Func _SetIP($ipaddr) FileDelete("netconf.txt") FileDelete("netconf2.txt") $sCommand="netsh -c interface dump > netconf.txt" _RunDOS( $sCommand ) $file = FileOpen("netconf.txt", 0) ; Check if file opened for reading OK If $file = -1 Then MsgBox(0, "Error", "Unable to open file.") Exit EndIf ; Read in lines of text until the EOF is reached While 1 $line = FileReadLine($file) If @error = -1 Then ExitLoop $result = StringLeft($line, 16) if $result=="set address name" then $line=EditLine($line, $ipaddr) $file2 = FileOpen("netconf2.txt", 1) ; Check if file opened for writing OK If $file2 = -1 Then MsgBox(0, "Error", "Unable to open file.") Exit EndIf FileWriteLine($file2, $line) FileClose($file2) Wend FileClose($file) ;MsgBox(0, "Configuring IP Address", "Setting IP to " & $ipaddr & ".") $sCommand="netsh -f netconf2.txt" _RunDOS( $sCommand ) EndFunc Func _ResetIP() ;MsgBox(0, "Configuring IP Address", "Resetting IP Address.") $sCommand="netsh -f netconf.txt" _RunDOS( $sCommand ) FileDelete("netconf.txt") FileDelete("netconf2.txt") EndFunc Func EditLine($line, $ipaddr) $result = StringInStr($line, "source") $firsthalf = StringLeft($line, $result-1) $line=$firsthalf & "source=static addr=" & $ipaddr & " mask=255.255.0.0" return($line) EndFunc