a6m1n0 Posted July 30, 2005 Posted July 30, 2005 Hi. I am trying to determine the MAC address of the active network connection and write to text file. I have found the examples in the help & forum for accessing the registry of the system, how to determine what the active connection is (LAN, Dial-up, etc) but nothing on MAC address. I have searched registry, but all I see is the "NetCfgInstanceId" and not the MAC. I am still pretty new to AutoIt...I have only written some small, very simple programs. This though has me stumped. And how to handle several NIC's MAC? I only want the 'active' one. The target machines should only have one, but might have two (wireless and 10/100), but only one would be active. Thanks.
LxP Posted July 30, 2005 Posted July 30, 2005 (edited) Something like:runWait(@comSpec & ' /c ipconfig /all > "' & @tempDir & '\ipconfig.txt"')will get the MAC address into a text file, which you could then parse. (Edit: missing double quote.) Edited July 30, 2005 by LxP
a6m1n0 Posted July 30, 2005 Author Posted July 30, 2005 Thanks LxP! I can definitely work with that. Question though: Is there no way then to get the value from the registry? Or discern the value from the NetCfgInstanceId? If that is indeed the MAC? Just curious. Again, thanks.
blindwig Posted July 30, 2005 Posted July 30, 2005 I don't know how to do it with native commands or DLL calls or objects or anything fancy like that, but I did once write a BAT file to get this info from IPCONFIG /ALL. The "Physical Address" is the MAC address, and disabled NICs are not displayed. My UDF Threads:Pseudo-Hash: Binary Trees, Flat TablesFiles: Filter by Attribute, Tree List, Recursive Find, Recursive Folders Size, exported to XMLArrays: Nested, Pull Common Elements, Display 2dSystem: Expand Environment Strings, List Drives, List USB DrivesMisc: Multi-Layer Progress Bars, Binary FlagsStrings: Find Char(s) in String, Find String in SetOther UDF Threads I Participated:Base64 Conversions
a6m1n0 Posted July 30, 2005 Author Posted July 30, 2005 Ok, so output to text and parse text. Gotcha. I guess this means I can use getmac' as well? Thanks
LxP Posted July 30, 2005 Posted July 30, 2005 Parsing a program's output isn't the most elegant solution but it's definitely the easiest. I did a quick Google for ideas but a lot of registry locations didn't work on my XP system.Here's some (presumably) VBS I came across:Set NetAdapterSet = GetObject("winmgmts:{impersonationLevel=impersonate}").ExecQuery("select * from Win32_NetworkAdapter") for each NetAdapter in NetAdapterSet wscript.echo NetAdapter.MACAddress nextif anyone can translate that.
a6m1n0 Posted July 30, 2005 Author Posted July 30, 2005 Awesome. I appreciate the effort. I will try parsing the text file to return the mac address back to AutoIt. This is really what I am trying to do. I need the MAC as a string. I am trying to write a net client (no, not .NET) that will uniquely identify the PC based on MAC. I do not want to use the actual MAC, but a hashed value (say md5($MAC)). I think though this regkey, HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\NetworkCards will provide me with enough information to get/generate a unique id of some sort. One more thing I am wondering: can the VISA functions be used to obtain the MAC from the actual device? Just curious if anyone knows. Seems like overkill for my project but am curious. Again thanks for all the advice/info.
Lazycat Posted July 30, 2005 Posted July 30, 2005 Another snippet: if you know IP of adapter (you most likely is) you can use this function to translate addresses (this is Ejoc's func if I'm recall right): expandcollapse popup$MAC = _GetMACFromIP ("192.168.0.1") MsgBox (0, "MAC Value", $MAC) Func _GetMACFromIP ($sIP) Local $MAC,$MACSize Local $i,$s,$r,$iIP ;Create the struct ;{ ; char data[6]; ;}MAC $MAC = DllStructCreate("byte[6]") ;Create a pointer to an int ; int *MACSize; $MACSize = DllStructCreate("int") ;*MACSize = 6; DllStructSetData($MACSize,1,6) ;call inet_addr($sIP) $r = DllCall ("Ws2_32.dll", "int", "inet_addr",_ "str", $sIP) $iIP = $r[0] ;Make the DllCall $r = DllCall ("iphlpapi.dll", "int", "SendARP",_ "int", $iIP,_ "int", 0,_ "ptr", DllStructGetPtr($MAC),_ "ptr", DllStructGetPtr($MACSize)) ;Format the MAC address into user readble format: 00:00:00:00:00:00 $s = "" For $i = 0 To 5 If $i Then $s = $s & ":" $s = $s & Hex(DllStructGetData($MAC,1,$i+1),2) Next ;Must free the memory after it is used DllStructDelete($MAC) DllStructDelete($MACSize) ;Return the user readble MAC address Return $s EndFunc Of course, this is beta stuff. Koda homepage ([s]Outdated Koda homepage[/s]) (Bug Tracker)My Autoit script page ([s]Outdated mirror[/s])
Wus Posted July 30, 2005 Posted July 30, 2005 a burning cuestion of mine is whether or not you can go from amc address to ip?
JavaCupiX Posted June 17, 2008 Posted June 17, 2008 (edited) I stumbled accross this article while searching for a way to get the MAC adresses from a computer... so I translated the VBS code into AutoIt $objWMIService = ObjGet("winmgmts:{impersonationLevel=impersonate}") $netAdapterSet = $objWMIService.ExecQuery("select * from Win32_NetworkAdapter") For $netAdapter in $netAdapterSet MsgBox(0, "", $netAdapter.MACAddress) Next $objNetwork = "" $netAdapterSet = "" EDIT: as you may notice while using this code it gives you a lot of different MAC Adresses, this is because it will output the MAC adress of the WAN/L2TP/Bluetooth/Firewire too... i recommand using MsgBox(0, "", "MAC" & $netAdapter.MACAddress & @CRLF & "Type:" & $netAdapter.AdapterType & @CRLF & "Device name:" & $netAdapter.Caption) to understand what it's all about... Edited June 17, 2008 by JavaCupiX
PartyPooper Posted June 17, 2008 Posted June 17, 2008 If you're using XP, how about something as simple as the DOS command getmac in an AutoIt runWait command like that shown above. It (getmac) can output several different formats so have a play around with it to see which suits you (type getmac /? in a cmd window for help).
JavaCupiX Posted June 17, 2008 Posted June 17, 2008 (edited) Sorry but I hate using RunWait stuff when Microsoft is so kind to provide us with a nice WMI interface. I can never be sure what happens with a RunWait... if one day the IT Staff decides to deactivate that command for the users it could take days before I think about "the program which uses a RunWait("ipconfig /all") or RunWait('getmac')"... But thanks for the tip, didn't know that "getmac" thing... can be usefull Cleaner is better! Edited June 17, 2008 by JavaCupiX
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