Rav1 0 Posted July 9, 2014 Hey gang. I have a script that I am working with that I pieced together (I'm learning) that I was hoping someone can help me with. I am trying to read the ipconfig /all cmd window and get the dhcp server address. The script works 80% of the time but occasionally the script returns the line below the dhcp server address. for example: 1.1.1.1 DNS Servers . . . . . . . . . . .>Exit code: 0 Time: 1.296 Thoughts? Thanks, Rav #include <MsgBoxConstants.au3> Local $sPrinter = InputBox("Add Printer", "Enter the complete Iprint name of the printer to add.", "Enter Printer Name", "", _ - 1, -1, 0, 0) ipconfig() Func ipconfig($lookfor = "DHCP Server") $cmd = Run(@Comspec & " /c ipconfig /all", "" , @SW_HIDE, 2+4) $Result = "" While 1 $line = StdoutRead($cmd) If @error Then Return "Error" if StringInStr($line,$lookfor) then ExitLoop WEnd $Data = StringSplit(StringStripWS($line,7),$lookfor,1) $Data = StringSplit($Data[2],":",1) $Data = StringStripWS($Data[2],7) ;FileWrite("Y:\files\printer_install.bat", @CRLF & "iprntcmd.exe -a ipp://"&$Data&"/ipp/"&$sPrinter) ConsoleWrite($Data) Return $Data EndFunc Share this post Link to post Share on other sites
JLogan3o13 1,623 Posted July 9, 2014 Why not just write it out to a temp file and then parse that? Pseudo, on my phone... Run(@Comspec & " /c ipconfig /all >" & @TempDir & "\MyIP.txt") "Profanity is the last vestige of the feeble mind. For the man who cannot express himself forcibly through intellect must do so through shock and awe" - Spencer W. Kimball How to get your question answered on this forum! Share this post Link to post Share on other sites
Exit 149 Posted July 9, 2014 #include <AutoItConstants.au3> #include <String.au3> $ipid = Run('"' & @ComSpec & '" /c ipconfig /all | find "DHCP-"', '', @SW_HIDE, $STDOUT_CHILD) ProcessWaitClose($iPID) $aDHCP = _StringBetween(StdoutRead($iPID),": ",@LF) MsgBox(262144, Default, $aDHCP[0], 0) App: Au3toCmd UDF: _SingleScript() Share this post Link to post Share on other sites
MHz 80 Posted July 9, 2014 Nice reply Exit. I will attempt to do a little more with cmd by using a for loop. $result = ipconfig() ConsoleWrite($result & @CRLF) Func ipconfig($lookfor = "DHCP Server") ; run cmd hidden with stdout Local $cmd = Run(@Comspec & ' /c @echo off & ' & _ 'for /f "usebackq tokens=2 delims=:" %# in (`ipconfig /all ^| find "' & $lookfor & '"`) do echo %#', "" , @SW_HIDE, 2 _ ) ; wait for the process to close ProcessWaitClose($cmd) ; return the result with each end trimmed of whitespace Return StringStripWS(StdoutRead($cmd), 3) EndFunc Share this post Link to post Share on other sites
jguinch 432 Posted July 9, 2014 You can also use WMI for that, with >network.au3 #Include "Network.au3" $aInfos = _GetNetworkAdapterInfos() For $i = 0 To UBound($aInfos) - 1 If StringInStr($aInfos[$i][20], ".") Then ConsoleWrite( "[" & $aInfos[$i][8] & "] DHCP Server : " & $aInfos[$i][20] & @CRLF) Next Spoiler Network configuration UDF, _DirGetSizeByExtension, _UninstallList Firefox ConfigurationArray multi-dimensions, Printer Management UDF Share this post Link to post Share on other sites
Chimp 700 Posted July 9, 2014 (edited) are you just experimenting with stdoutread or are you interested in network parameters? if you are intereste to network parameters then >also this link may be of interest: with that udf you can retrieve some network parameters in this way for example: (see comments inside the udf for details on returned values) #include <array.au3> #include "_NetworkStatistics.au3" ; get this from the following link: ; http://www.autoitscript.com/forum/topic/151920-network-interface-info-statistics-and-traffic/?p=1088781 Local $_net = _Network_IPAllAddressTable() _ArrayDisplay($_net) edit: added link Edited July 9, 2014 by Chimp 1 jguinch reacted to this small minds discuss people average minds discuss events great minds discuss ideas.... and use AutoIt.... Share this post Link to post Share on other sites
jguinch 432 Posted July 9, 2014 Chimp, thanks for the link ! It will be very usefull Spoiler Network configuration UDF, _DirGetSizeByExtension, _UninstallList Firefox ConfigurationArray multi-dimensions, Printer Management UDF Share this post Link to post Share on other sites
Chimp 700 Posted July 9, 2014 Chimp, thanks for the link ! It will be very usefull You are welcome...... but we have to thanks Ascend4ant small minds discuss people average minds discuss events great minds discuss ideas.... and use AutoIt.... Share this post Link to post Share on other sites
Rav1 0 Posted July 10, 2014 Thanks all! The information and examples are awesome. You guys help me learn so much and I can't say thanks enough. Share this post Link to post Share on other sites