Dougiefresh Posted November 15, 2007 Posted November 15, 2007 (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 November 15, 2007 by Dougiefresh
Klaatu Posted November 15, 2007 Posted November 15, 2007 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!
Thunder-man Posted November 15, 2007 Posted November 15, 2007 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
peter123 Posted November 15, 2007 Posted November 15, 2007 How about change your mac? can you change that too, witch autoit3?
Moderators SmOke_N Posted November 15, 2007 Moderators Posted November 15, 2007 (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 November 15, 2007 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.
Ghost21 Posted November 15, 2007 Posted November 15, 2007 (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 November 15, 2007 by Ghost21
Moderators SmOke_N Posted November 15, 2007 Moderators Posted November 15, 2007 (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 EndIfI 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 November 15, 2007 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.
A. Percy Posted November 19, 2007 Posted November 19, 2007 http://www.autoitscript.com/forum/index.ph...c=48545&hl= 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
BrettF Posted November 19, 2007 Posted November 19, 2007 omg i didn´t know run("getmac") http://www.microsoft.com/resources/documen...c.mspx?mfr=true Vist my blog!UDFs: Opens The Default Mail Client | _LoginBox | Convert Reg to AU3 | BASS.au3 (BASS.dll) (Includes various BASS Libraries) | MultiLang.au3 (Multi-Language GUIs!)Example Scripts: Computer Info Telnet Server | "Secure" HTTP Server (Based on Manadar's Server)Software: AAMP- Advanced AutoIt Media Player | WorldCam | AYTU - Youtube Uploader Tutorials: Learning to Script with AutoIt V3Projects (Hardware + AutoIt): ArduinoUseful Links: AutoIt 1-2-3 | The AutoIt Downloads Section: | SciTE4AutoIt3 Full Version!
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