 |
AutoHotkey Community Let's help each other out
|
| View previous topic :: View next topic |
| Author |
Message |
Pasukun
Joined: 16 Dec 2004 Posts: 84
|
Posted: Mon May 23, 2005 6:26 pm Post subject: Dectect MAC address |
|
|
Is there a way to detect MAC address of the local machine's network card?
I know I can find the Node name and IP address by using "A_ComputerName" and "A_IPAddress1".
It would be helpful to farther secure the script to only run on certain computer with the use of MAC address detection. This way I can create more risky scripts without worrying too much.
I know MAC address can be spoofed as well, but it is harder to do so and it will be better than nothing.  _________________
"the things we touch have no permanence. my master would say: there is nothing we can hold onto in this world.. only by letting go can we truly possess what is real..." |
|
| Back to top |
|
 |
Jon
Joined: 28 Apr 2004 Posts: 373
|
Posted: Mon May 23, 2005 7:11 pm Post subject: |
|
|
This is probably the easiest way although you can probably do it with an API call as well-
| Code: |
runwait, %comspec% /c ipconfig /all > c:\mac.txt, ,hide
Loop, Read, c:\mac.txt
{
ifinstring, A_LoopReadLine, Physical Address
{
MAC=%A_LoopReadLine%
break
}
}
StringRight, MAC, MAC, 18
msgbox, %MAC%
filedelete, c:\mac.txt
|
Last edited by Jon on Tue May 24, 2005 12:58 pm; edited 1 time in total |
|
| Back to top |
|
 |
niwi
Joined: 27 Feb 2005 Posts: 128 Location: Heidelberg, Germany
|
Posted: Tue May 24, 2005 10:58 am Post subject: |
|
|
Hi Jon,
the 14th line isn't always correct.
Pasukun, you should search the output of the "ipconfig /all" command for the line containig "physical address" (is this the correct translation?).
NiWi. |
|
| Back to top |
|
 |
Jon
Joined: 28 Apr 2004 Posts: 373
|
Posted: Tue May 24, 2005 12:58 pm Post subject: |
|
|
| niwi wrote: | Hi Jon,
the 14th line isn't always correct.
Pasukun, you should search the output of the "ipconfig /all" command for the line containig "physical address" (is this the correct translation?).
NiWi. |
Thanks, I've edited my script above |
|
| Back to top |
|
 |
Jon
Joined: 28 Apr 2004 Posts: 373
|
Posted: Tue May 24, 2005 1:32 pm Post subject: |
|
|
Another way without a text file using corrupts CMDret DLL
| Code: | ; CMDret DLL version 3.1.1 (or greater) required
ret1 := CMDret(COMSPEC " /C ipconfig/all")
Loop, Parse, ret1, `n
{
ifinstring, A_LoopField, Physical Address
{
MAC=%A_LoopField%
break
}
}
StringRight, MAC, MAC, 19
msgbox, %MAC%
CMDret(CMD)
{
VarSetCapacity(StrOut, 10000)
RetVal := DllCall("cmdret.dll\RunReturn", "str", CMD, "str", StrOut)
Return, %StrOut%
} |
|
|
| Back to top |
|
 |
Pasukun
Joined: 16 Dec 2004 Posts: 84
|
Posted: Tue May 24, 2005 6:34 pm Post subject: |
|
|
Thanks for the replies.
Yeah I was afraid of that..
Looks like the only way to get the MAC address value is to run "IPCONFIG /ALL" and use the "IfInString" command. _________________
"the things we touch have no permanence. my master would say: there is nothing we can hold onto in this world.. only by letting go can we truly possess what is real..." |
|
| Back to top |
|
 |
niwi
Joined: 27 Feb 2005 Posts: 128 Location: Heidelberg, Germany
|
Posted: Wed May 25, 2005 11:04 am Post subject: |
|
|
Hi Pasukun,
the MAC address is hard coded on the NICs. It is possible to set a new MAC address and overriding the original by setting a registry key. In this case you could read the address from the registry, but this is not really recommended. Changing the MAC address requires a good know how about networking, because this may make trouble in a network if you not really know what the MAC address is used for.
I think the best solution is to use ipconfig.
NiWi. |
|
| Back to top |
|
 |
niwi
Joined: 27 Feb 2005 Posts: 128 Location: Heidelberg, Germany
|
Posted: Thu May 26, 2005 11:57 am Post subject: |
|
|
Hi,
maybe you also can try to use a DLLCall ("IPHLPAPI.DLL\GetAdaptersInfo"...). But I haven't used this function yet so I have no experience what exactly is to do (parameters etc.). My first try call's Dr. Watson
NiWi. |
|
| Back to top |
|
 |
normel
Joined: 20 May 2005 Posts: 5 Location: NY, NY
|
Posted: Fri May 27, 2005 8:05 pm Post subject: |
|
|
Here's a little code you can use. It creates a vbscript, then executes it. This assumes you have W2K or later that supports WMI.
| Code: | ifExist,c:\wutemp\temp.vbs
filedelete,c:\wutemp\temp.vbs
fileappend,On Error Resume Next`n,c:\wutemp\temp.vbs
fileappend,Dim NumAdap(5)`n,c:\wutemp\temp.vbs
fileappend,set objFSO = CreateObject("Scripting.FileSystemObject")`n,c:\wutemp\temp.vbs
fileappend,Set f1 = objFSO.CreateTextFile("c:\wutemp\temp.txt"`, True)`n,c:\wutemp\temp.vbs
fileappend,Set objWMIService = GetObject("winmgmts:\\127.0.0.1\root\CIMV2")`n,c:\wutemp\temp.vbs
fileappend,Set colItems = objWMIService.ExecQuery("SELECT * FROM Win32_NetworkAdapter")`n,c:\wutemp\temp.vbs
fileappend,i = 0`n,c:\wutemp\temp.vbs
fileappend,For Each objItem In colItems`n,c:\wutemp\temp.vbs
fileappend,if objItem.MACAddress <> "" then`n,c:\wutemp\temp.vbs
fileappend,i = i + 1`n,c:\wutemp\temp.vbs
fileappend,NumAdap(i) = objItem.MACAddress`n,c:\wutemp\temp.vbs
fileappend,end if`n,c:\wutemp\temp.vbs
fileappend,Next`n,c:\wutemp\temp.vbs
fileappend,For j = 1 to i`n,c:\wutemp\temp.vbs
fileappend,f1.writeline(NumAdap(j))`n,c:\wutemp\temp.vbs
fileappend,Next`n,c:\wutemp\temp.vbs
fileappend,f1.Close,c:\wutemp\temp.vbs
run,c:\wutemp\temp.vbs
Loop, Read, c:\wutemp\temp.txt
{
MAC = %A_LoopReadLine%
msgbox,MAC = %MAC%
}
sleep 5000
ifExist,c:\wutemp\temp.vbs
filedelete,c:\wutemp\temp.vbs
ifExist,c:\wutemp\temp.txt
filedelete,c:\wutemp\temp.txt
|
You'll have to play with the last few lines, if you want to get rid of the temporary files the script creates. If you use runwait instead of run, it will work every time, and you won't need the sleep 5000 line, but it also runs a lot slower before the msgbox popped up.
The script will work with multiple NICs that have MAC addresses. |
|
| Back to top |
|
 |
|
|
You can post new topics in this forum You can reply to topics in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|