Jump to content

how to solve this ?


mark2
 Share

Recommended Posts

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

Link to comment
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

 

 

image.jpeg.9f1a974c98e9f77d824b358729b089b0.jpeg Chimp

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

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...