Jump to content

How to get value from Stdout


 Share

Recommended Posts

Hi All,

i am going to get the interface name of the connection that is connected in my PC.

tried using stdoutread but have no idea how to get the value. 

#include <Constants.au3>

Global $DOS, $Message

$DOS = Run(@ComSpec & " /c netsh interface show interface", "", @SW_HIDE, $STDERR_CHILD + $STDOUT_CHILD)
ProcessWaitClose($DOS)
$Message = StdoutRead($DOS)

;have no idea for how to get the value of the connected connection ?

MsgBox(0, "", $Message)

appreciate for the help. thanks.

Link to comment
Share on other sites

Try something like this:

#include <Array.au3>
#include <Constants.au3>

Global $sDOS
$iPID = Run(@ComSpec & " /c netsh interface show interface", "", @SW_HIDE, $STDERR_CHILD + $STDOUT_CHILD)

While 1
    $sDOS &= StdoutRead($iPID) ; Read the Stdout stream of the PID returned by Run.
    If @error Then ; Exit the loop if the process closes or StdoutRead returns an error.
        ExitLoop
    EndIf
WEnd
ConsoleWrite($sDOS & @CRLF)

$aFilter = StringRegExp($sDOS, "(?m).+\hConnected.+\h+\h+(.*)\s", 3)
_ArrayDisplay($aFilter, "Interface Name", "", 0, Default, "Interface Name")

 

Please don't send me any personal message and ask for support! I will not reply!

Selection of finest graphical examples at Codepen.io

The own fart smells best!
Her 'sikim hıyar' diyene bir avuç tuz alıp koşma!
¯\_(ツ)_/¯  ٩(●̮̮̃•̃)۶ ٩(-̮̮̃-̃)۶ૐ

Link to comment
Share on other sites

Hi UEZ,

please try to see my script below. what i am trying to do is set my arp as a static automatically after detect an different mac address between the first and second file.

tried to use manual interface first for testing but also didnt work for set it to be static. could you please help to solve it (with an automatic interface name instead of manual)?

thanks alot

 

#RequireAdmin
#include <Constants.au3>

Local $CompIP = @IPAddress1
Local $Gateway = DefaultGateway($CompIP)
Global $file,$file2,$time, $TheCommand
Global $interface="Wi-Fi" ;manual interface


;------------------------------------------------------------------------------------------

$concheck = DllCall("WinInet.dll","int","InternetGetConnectedState","int_ptr",0,"int",0)

If  $concheck[0] Then

    $comand=" /c arp "
    $comand=$comand&$Gateway&" -g>D:\ORIGINAL.txt"
    $cmd = Run(@Comspec & $comand, "", @SW_HIDE)

    $comand=" /c arp "
    $comand=$comand&$Gateway&" -g>D:\UPDATE.txt"

;------------------------------------------------------------------------------------------

    DO
    $cmd = Run(@Comspec & $comand, "", @SW_HIDE)

;------------------------------------------------------------------------------------------

    sleep ($time)

    $file=FileOpen("D:\Update.txt",0)
    $first=FileReadLine($file, 4)
    $first=StringTrimRight($first,15)
    $first=StringTrimLeft($first,24)
    $file=FileClose("D:\Update.txt")

    $file2=FileOpen("D:\ORIGINAL.txt",0)
    $second=FileReadLine($file2, 4)
    $second=StringTrimRight($second,15)
    $second=StringTrimLeft($second,24)
    $file2=FileClose("D:\ORIGINAL.txt")


    if $first=$second Then
        $time=5000
    Else
        MsgBox(0,"DETECTION", "YOUR MAC ADDRESS WAS CHANGED, TRYING TO RESOLVING")
        $TheComand= "netsh -c ""interface ipv4"" set neighbors " &$interface&" "" "&$Gateway&" "" """&$first&""""
        RunWait($TheCommand, "", @SW_HIDE, $STDERR_CHILD + $STDOUT_CHILD)
    EndIf

        local $exit=0
        until $exit=1

Else
        MsgBox(0,"","you are not connected")
        RunWait($concheck[0])
EndIf

;------------------------------------------------------------------------------------------


;------------------------------------------------------------------------------------------
Func DefaultGateway($a)
        Local $vObjWMI = ObjGet("winmgmts:\\"&$a&"\root\cimv2")
        $vObjItems = $vObjWMI.ExecQuery('SELECT * FROM Win32_NetworkAdapterConfiguration WHERE IPEnabled=True')
        If IsObj($vObjItems) Then
            For $vObjItem In $vObjItems
                For $i = 0 To UBound($vObjItem.IPAddress) - 1
                    If $vObjItem.IPAddress($i) == @IPAddress1 Then
                        Return SetError(0, 0, $vObjItem.DefaultIPGateway($i))
                    EndIf
                Next
            Next
        EndIf
        Return SetError(1, 0, "")
EndFunc

;------------------------------------------------------------------------------------------

 

Link to comment
Share on other sites

Can you provide Update.txt / ORIGINAL.txt and explain which differences you are looking for.

 

I'm not familiar with the netsh command and I don't want to misconfigure my settings.

Please don't send me any personal message and ask for support! I will not reply!

Selection of finest graphical examples at Codepen.io

The own fart smells best!
Her 'sikim hıyar' diyene bir avuç tuz alıp koşma!
¯\_(ツ)_/¯  ٩(●̮̮̃•̃)۶ ٩(-̮̮̃-̃)۶ૐ

Link to comment
Share on other sites

hi, i have modified my script and now it is work using manual interface name.

now the problem is how to get the interface name automatically so my script will work as expected

 

#RequireAdmin

Local $CompIP = @IPAddress1
Local $Gateway = DefaultGateway($CompIP)
Global $file, $file2, $time
Global $interface="Wi-Fi"

;------------------------------------------------------------------------------------------

$concheck = DllCall("WinInet.dll","int","InternetGetConnectedState","int_ptr",0,"int",0)

If  $concheck[0] Then

    $comand=" /c arp "
    $comand=$comand&$Gateway&" -g>D:\ORIGINAL.txt"
    $cmd = Run(@Comspec & $comand, "", @SW_HIDE)

    $comand=" /c arp "
    $comand=$comand&$Gateway&" -g>D:\UPDATE.txt"

;------------------------------------------------------------------------------------------

    DO
    $cmd = Run(@Comspec & $comand, "", @SW_HIDE)

;------------------------------------------------------------------------------------------

    sleep ($time)

    $file=FileOpen("D:\Update.txt",0)
    $first=FileReadLine($file, 4)
    $first=StringTrimRight($first,15)
    $first=StringTrimLeft($first,24)
    $file=FileClose("D:\Update.txt")

    $file2=FileOpen("D:\ORIGINAL.txt",0)
    $second=FileReadLine($file2, 4)
    $second=StringTrimRight($second,15)
    $second=StringTrimLeft($second,24)
    $file2=FileClose("D:\ORIGINAL.txt")


    if $first=$second Then
        $time=5000
    Else
        MsgBox(0,"DETECTION", "YOUR MAC ADDRESS WAS CHANGED, TRYING TO RESOLVING")
        $comand=" /c netsh -c ""interface ipv4"" set neighbors "&$interface&" "&$Gateway&" "&$second&" "
        $cmd = Run(@Comspec & $comand, "", @SW_HIDE)
        sleep(5000)

    EndIf

        local $exit=0
        until $exit=1

Else
        MsgBox(0,"","you are not connected")
        RunWait($concheck[0])
EndIf

;------------------------------------------------------------------------------------------


;------------------------------------------------------------------------------------------
Func DefaultGateway($a)
        Local $vObjWMI = ObjGet("winmgmts:\\"&$a&"\root\cimv2")
        $vObjItems = $vObjWMI.ExecQuery('SELECT * FROM Win32_NetworkAdapterConfiguration WHERE IPEnabled=True')
        If IsObj($vObjItems) Then
            For $vObjItem In $vObjItems
                For $i = 0 To UBound($vObjItem.IPAddress) - 1
                    If $vObjItem.IPAddress($i) == @IPAddress1 Then
                        Return SetError(0, 0, $vObjItem.DefaultIPGateway($i))
                    EndIf
                Next
            Next
        EndIf
        Return SetError(1, 0, "")
EndFunc

;------------------------------------------------------------------------------------------

 

Link to comment
Share on other sites

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
 Share

  • Recently Browsing   0 members

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