mark2 Posted February 8, 2016 Share Posted February 8, 2016 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 More sharing options...
mark2 Posted February 8, 2016 Author Share Posted February 8, 2016 Or is there any way to get the default gateway of the router directly Link to comment Share on other sites More sharing options...
mark2 Posted February 8, 2016 Author Share Posted February 8, 2016 I mean router ip address Link to comment Share on other sites More sharing options...
Gianni Posted February 8, 2016 Share Posted February 8, 2016 Here are some snippets found elsewhere and assembled in this draft: expandcollapse popupLocal $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 Chimp small minds discuss people average minds discuss events great minds discuss ideas.... and use AutoIt.... Link to comment Share on other sites More sharing options...
mark2 Posted February 9, 2016 Author Share Posted February 9, 2016 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. Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now