Sign in to follow this  
Followers 0
mark2

how to solve this ?

5 posts in this topic

i am trying to get the all ip and mac address and then write it into 2 file.

1st file : will get the all ip address with mac address

2nd file : only get the line 4 value from 1st file.

file as attached, it work when i double run the script but how to make it work just with the first execute.

thanks for the help.

testest.rar

Share this post


Link to post
Share on other sites



Or is there any way to get the default gateway of the router directly

Share this post


Link to post
Share on other sites

I mean router ip address

Share this post


Link to post
Share on other sites

Here are some snippets found elsewhere and assembled in this draft:

Local $sComputername = @IPAddress1 ; @ComputerName

Local $sDefaultGateway = _WMI_GetDefaultGateway($sComputername)
Local $sMacAddress = _GetMACFromIP($sDefaultGateway)

MsgBox(0, "Default Gateway", "IP:" & @TAB & $sDefaultGateway & @CRLF & "MAC:" & @TAB & $sMacAddress)

Func _WMI_GetDefaultGateway($Computername)
    if Ping($Computername, 500) Then
        Local $vObjWMI = ObjGet("winmgmts:\\" & $Computername & "\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
                        ; ConsoleWrite("IP addres  : " & $vObjItem.IPAddress($i) & @CRLF)
                        ; ConsoleWrite("MAC addres : " & $vObjItem.MACAddress($i) & @CRLF)
                        ; ConsoleWrite("Subnet Mask: " & $vObjItem.IPSubnet($i) & @CRLF)
                        ; ConsoleWrite("D. gateway : " & $vObjItem.DefaultIPGateway($i) & @CRLF)
                        Return SetError(0, 0, $vObjItem.DefaultIPGateway($i)) ; got it
                    EndIf
                Next
            Next
        EndIf
    EndIf
    Return SetError(1, 0, "") ; problems
EndFunc   ;==>_WMI_GetDefaultGateway

Func _GetMACFromIP($sIP)
    Local $MAC, $MACSize
    Local $i, $s, $r, $iIP
    $MAC = DllStructCreate("byte[6]")
    $MACSize = DllStructCreate("int")
    DllStructSetData($MACSize, 1, 6)
    $r = DllCall("Ws2_32.dll", "int", "inet_addr", "str", $sIP)
    $iIP = $r[0]
    $r = DllCall("iphlpapi.dll", "int", "SendARP", "int", $iIP, "int", 0, "ptr", DllStructGetPtr($MAC), "ptr", DllStructGetPtr($MACSize))
    $s = ""
    For $i = 0 To 5
        If $i Then $s &= ":"
        $s = $s & Hex(DllStructGetData($MAC, 1, $i + 1), 2)
    Next
    Return $s
EndFunc   ;==>_GetMACFromIP

 


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

Thanks chimp ! 

one more question, is there any ebook or web or any thread in this forum is about WMI scripting ? i am going to learn about WMI scripting. thanks.

 

Share this post


Link to post
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
Sign in to follow this  
Followers 0