franov Posted April 19, 2006 Share Posted April 19, 2006 (edited) Hello, I want to make a script (our I should say I need someone here to make one for me...cause I have not suceeded so far...lol) I need a basic sript to release and renew IP I want it to open the command prompt (normally done using start/run type "cmd") than in the command prompt i need to type "ipconfig" than "ipconfig/release" than "ipconfig/renew" than close the command promp after a few sec once i know that it worked. so far I have not been able to send input at all. I'm really new at scripting so don't flame me plz, my only script so far is one that click in a loop..lol I have to start somewhere thx all Edited April 19, 2006 by franov Link to comment Share on other sites More sharing options...
Xenobiologist Posted April 19, 2006 Share Posted April 19, 2006 Hi, #include <Process.au3> $rc0= _RunDos("ipconfig /release") $rc1 = _RunDos("ipconfig /renew") So long, Mega Scripts & functions Organize Includes Let Scite organize the include files Yahtzee The game "Yahtzee" (Kniffel, DiceLion) LoginWrapper Secure scripts by adding a query (authentication) _RunOnlyOnThis UDF Make sure that a script can only be executed on ... (Windows / HD / ...) Internet-Café Server/Client Application Open CD, Start Browser, Lock remote client, etc. MultipleFuncsWithOneHotkey Start different funcs by hitting one hotkey different times Link to comment Share on other sites More sharing options...
neogia Posted April 19, 2006 Share Posted April 19, 2006 ...I want someone here to make one for me...I understand what you mean by this, but others might not. Watch how you word things. You should take a look at Run("ipconfig /release") Run("ipconfig /renew") [u]My UDFs[/u]Coroutine Multithreading UDF LibraryStringRegExp GuideRandom EncryptorArrayToDisplayString"The Brain, expecting disaster, fails to find the obvious solution." -- neogia Link to comment Share on other sites More sharing options...
franov Posted April 19, 2006 Author Share Posted April 19, 2006 Works very well, awesome ,thx all Link to comment Share on other sites More sharing options...
exodius Posted April 20, 2006 Share Posted April 20, 2006 (edited) Works very well, awesome ,thx all One thing I'd like to add to the end of what's already been suggested... If you want to verify that it worked then I'd consider something like what you get from: expandcollapse popup#include <process.au3> #include <file.au3> ; The ">" will pipe the output to a file which you can then read with AutoIt to see what happened. _RunDOS ( "ipconfig /release > release.txt" ) _RunDOS ( "ipconfig /renew > renew.txt" ) ;Reading "release.txt" into an array, then searching it for mention of the ethernet adapter you're looking for. Once we find that we'll change the $AdapterCheck from 0 to 1 so the next time we see "IP Address" in a line we'll grab what the IP is from it. This will filter out other IPs if you have more than one ethernet adapter in your machine. Dim $releasecheck _FileReadToArray ( "release.txt", $releasecheck ) $AdapterCheck = 0 For $x = 1 To $releasecheck[0] If StringInStr ( $releasecheck[$x], "Name of your ethernet adapter here per release.txt") Then $AdapterCheck = 1 EndIf If StringInStr ( $releasecheck[$x], "IP Address") And $AdapterCheck = 1 Then $releasesplit = StringSplit ( $releasecheck[$x], ":" ) $ReleaseIP = StringStripWS ( $releasesplit[2], 8 ) $AdapterCheck = 0 EndIf Next ;Doing the same for "renew.txt" as we did for "release.txt" Dim $renewcheck _FileReadToArray ( "renew.txt", $renewcheck ) $AdapterCheck = 0 For $x = 1 To $renewcheck[0] If StringInStr ( $renewcheck[$x], "Name of your ethernet adapter here per renew.txt") Then $AdapterCheck = 1 EndIf If StringInStr ( $renewcheck[$x], "IP Address") And $AdapterCheck = 1 Then $renewsplit = StringSplit ( $renewcheck[$x], ":" ) $RenewIP = StringStripWS ( $renewsplit[2], 8 ) $AdapterCheck = 0 EndIf Next ;FileDelete ( "release.txt" ) You can delete this file arbitrarily after you know what ethernet adapter you're looking for ;FileDelete ( "renew.txt" ) You can delete this file arbitrarily after you know what ethernet adapter you're looking for ;You now know what the IP was when it was release and what it was after it was renewed. Instead of this message box you could set up an If...Then statement on what to do next to check if the IP you got is one that you intended to get (or at least to check if it's one you don't want like 0.0.0.0 or 169.254.* ) MsgBox ( 0, "", "Released IP ----> " & $ReleaseIP & @CRLF & "Renewed IP ----> " & $RenewIP ) I'd look any of the functions that you're not familiar with up in the help file. Edited April 20, 2006 by exodius Link to comment Share on other sites More sharing options...
neogia Posted April 20, 2006 Share Posted April 20, 2006 These two functions return the new IP address (should be 0.0.0.0 after _Release()) or return "", and set @error to 1 if there was a problem. MsgBox(0,"", _Release()) MsgBox(0,"", _Renew()) Func _Release() $pid = Run("ipconfig /release", "", "", 7) $return = StdoutRead($pid) $ipLine = StringRegExp($return, "IP Address.*?:(.*?)\n", 1) If @extended == 1 Then Return $ipLine[0] Else SetError(1) Return "";IP already released EndIf EndFunc Func _Renew() $pid = Run("ipconfig /renew", "", "", 7) $return = StdoutRead($pid) $ipLine = StringRegExp($return, "IP Address.*?:(.*?)\n", 1) If @extended == 1 Then Return $ipLine[0] Else SetError(1) Return "";Error in renewing IP address EndIf EndFunc [u]My UDFs[/u]Coroutine Multithreading UDF LibraryStringRegExp GuideRandom EncryptorArrayToDisplayString"The Brain, expecting disaster, fails to find the obvious solution." -- neogia 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