Jump to content

Recommended Posts

Posted

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
  • Solution
Posted

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

:)

Posted

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
Posted (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 by Chimp

 

image.jpeg.9f1a974c98e9f77d824b358729b089b0.jpeg Chimp

small minds discuss people average minds discuss events great minds discuss ideas.... and use AutoIt....

Posted

Chimp, thanks for the link ! It will be very usefull

 

You are welcome...... but we have to thanks Ascend4ant :)

 

image.jpeg.9f1a974c98e9f77d824b358729b089b0.jpeg Chimp

small minds discuss people average minds discuss events great minds discuss ideas.... and use AutoIt....

Posted

Thanks all! The information and examples are awesome.  You guys help me learn so much and I can't say thanks enough.

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...