Jump to content

Recommended Posts

Posted (edited)

Use this function to pull the MAC addresses from the computer.

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

$MAC = _GetMACAddress()
_ArrayDisplay( $MAC )

Func _GetMACAddress()
    local $MAC[1]

    RunWait( @comspec & " /c ipconfig /all > OUTPUT.TXT", @TempDir, @SW_HIDE )
    $File = FileOpen( @TempDir & "\OUTPUT.TXT", 0 )
    while 1
        $Line = FileReadLine( $File)
        if @error then ExitLoop
        if StringInStr( $Line, "Physical Address" ) <> 0 then _ArrayAdd( $MAC, StringMid( $Line, 45, 17 ) )
    WEnd
    FileClose( $File )
    FileDelete( @TempDir & "\OUTPUT.TXT" )
    return $MAC
EndFunc
Edited by Dougiefresh
Posted

How about getting the Mac address of any computer on your network:

Func _MACAddress($sComputerName)
   Local $i, $oAdapter, $sMAC = ''
   If ($sComputerName = '.') Then $sComputerName = @ComputerName
   If (Ping($sComputerName, 1000) > 0) Then
      Local Const $sFuncName = ObjEvent("AutoIt.Error")
      ObjEvent("AutoIt.Error","__DummyCOMError")
      Local Const $oWMIService = ObjGet('winmgmts:\\' & $sComputerName & '\root\CIMV2')
      If IsObj($oWMIService) Then
         Local Const $colAdapters = $oWMIService.ExecQuery('SELECT * FROM Win32_NetworkAdapterConfiguration WHERE IPEnabled = True')
         If IsObj($colAdapters) Then
            For $oAdapter In $colAdapters
               If IsArray($oAdapter.IPAddress) Then
                  For $i = 0 To UBound($oAdapter.IPAddress)-1
                     If ($oAdapter.IPAddress($i) <> "0.0.0.0") Then
                        $sMAC = $oAdapter.MACAddress
                        ExitLoop 2
                     EndIf
                  Next
               EndIf
            Next
         EndIf
      EndIf
      If $sFuncName <> '' Then ObjEvent("AutoIt.Error", $sFuncName)
   EndIf
   Return StringReplace($sMAC, ':', '-')
EndFunc

Func __DummyCOMError()
   SetError(1) ; something to check for when this function returns
EndFunc

Returns an empty string if no Mac address could be found.

Pass "." to get the Mac address of your own computer.

My Projects:DebugIt - Debug your AutoIt scripts with DebugIt!
Posted

THX,

that is very easy... also for german User:

Use "Physikalische Adresse"

;~       if StringInStr( $Line, "Physical Address" ) <> 0 then _ArrayAdd( $MAC, StringMid( $Line, 45, 17 ) )
            if StringInStr( $Line, "Physikalische Adresse" ) <> 0 then _ArrayAdd( $MAC, StringMid( $Line, 45, 17 ) )

greeting

thunder-man

  • Moderators
Posted (edited)

Could take the language issue out of the picture completely really:

#include <Array.au3>
$b = _GetMACAddress()
_ArrayDisplay($B)

Func _GetMACAddress()
    local $sText, $iPID
    $iPID = Run(@ComSpec & " /c ipconfig /all", '', @SW_HIDE, 6)
    While 1
        $sText &= StdoutRead($iPID)
        If @error Then ExitLoop
    WEnd
    Return StringRegExp($sText, "(?s)(?i)([\w|\d]{2}\-[\w|\d]{2}\-[\w|\d]{2}\-[\w|\d]{2}\-[\w|\d]{2}\-[\w|\d]{2})", 3)
EndFunc

Edited by SmOke_N

Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.

Posted (edited)

Could take the language issue out of the picture completely really:

#include <Array.au3>
$b = _GetMACAddress()
_ArrayDisplay($B)

Func _GetMACAddress()
    local $sText, $iPID
    $iPID = Run(@ComSpec & " /c ipconfig /all", '', @SW_HIDE, 6)
    While 1
        $sText &= StdoutRead($iPID)
        If @error Then ExitLoop
    WEnd
    Return StringRegExp($sText, "(?s)(?i)([\w|\d]{2}\-[\w|\d]{2}\-[\w|\d]{2}\-[\w|\d]{2}\-[\w|\d]{2}\-[\w|\d]{2})", 3)
EndFunc

I do it different as well...

If GUICtrlRead($Checkbox46) = 1 Then

$get = Run("getmac /S " & "\\Domain" /FO table /NH", @ScriptDir, @SW_HIDE, $STDOUT_CHILD)

While ProcessExists($get)

Sleep(100)

WEnd

$StdOut = StdoutRead($get)

$mac = StringLeft(StringStripWS($StdOut, 8), 17)

msgbox(4000,"Mac Address",$mac)

Else

EndIf

Edited by Ghost21
  • Moderators
Posted (edited)

I do it different as well...

If GUICtrlRead($Checkbox46) = 1 Then

$get = Run("getmac /S " & "\\Domain" /FO table /NH", @ScriptDir, @SW_HIDE, $STDOUT_CHILD)

While ProcessExists($get)

Sleep(100)

WEnd

$StdOut = StdoutRead($get)

$mac = StringLeft(StringStripWS($StdOut, 8), 17)

msgbox(4000,"Mac Address",$mac)

Else

EndIf

I use WMI... but I do use the above that I posted (a little revised for the ethernet mac only). I was just providing a solution similar to the OP's post, that solved the language issue... that your's would still have to deal with. Edited by SmOke_N

Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.

Posted

Só o que posso lhe dizer, bom é quando faz mal!My work:Au3Irrlicht - Irrlicht for AutoItMsAgentLib - An UDF for MSAgentAu3GlPlugin T2 - A 3D plugin for AutoIt...OpenGl Plugin - The old version of Au3GlPlugin.MAC Address Changer - Changes the MAC AddressItCopter - A dragonfly R/C helicopter simulator

VW Bug user

Pinheiral (Pinewood) city:

http://pt.wikipedia.org/wiki/Pinheiral

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