All Forums |
Register |
Login |
Search |
Subscriptions |
My Profile |
Inbox |
Tool Warehouse |
FAQs |
Resources |
Help |
Member List |
Address Book |
Logout |
|
|
how to get mac address
|
Logged in as: Guest |
Users viewing this topic: none |
|
Login |
|
|
how to get mac address - Nov. 8, '05, 3:53:49 AM
|
|
|
asfoster
Posts: 34
Joined: Oct. 18, '05,
From: Lincolnshire UK
Status: offline
|
Does anyone know how to get the network card mac address through interix. On Linux this is returned using the hostid command but Interix does not appear to support this. This is very useful if you want to lock sofware to run on a specified machine only.
Thanks
_____________________________
Andy Foster
|
|
|
RE: how to get mac address - Nov. 8, '05, 10:36:07 AM
|
|
|
Rodney
Posts: 3142
Joined: Jul. 9, '02,
From: /Tools lab
Status: online
|
You can run the command line program ipconfig /all to get this info.
It's labeled as "Physical Address".
This is invoking a Win32 program, but you can process the output.
The other way is to use the registry API's to get the information.
|
|
|
RE: how to get mac address - Nov. 8, '05, 11:06:06 AM
|
|
|
asfoster
Posts: 34
Joined: Oct. 18, '05,
From: Lincolnshire UK
Status: offline
|
Thanks for this Rodney.
I presume the Registry API is a win32 API - is it exposed to interix or is there a posix API?
|
|
|
RE: how to get mac address - Nov. 8, '05, 11:27:44 AM
|
|
|
jsnively
Posts: 17
Joined: Dec. 7, '03,
From: Columbus, Ohio
Status: offline
|
You can make a tiny Win32 program to read the mac address. Here's the guts of it:
#include <windows.h>
#include <stdio.h>
#include <time.h>
#include <stdlib.h>
#include <iphlpapi.h>
int macaddr(CHAR* buf)
{
PIP_ADAPTER_INFO pai = NULL;
DWORD dwSize = 0;
int found = 0;
// Get size of buffer needed:
GetAdaptersInfo(NULL, &dwSize);
pai = (PIP_ADAPTER_INFO)GlobalAlloc(GPTR, dwSize);
GetAdaptersInfo(pai, &dwSize);
PIP_ADAPTER_INFO p = pai;
while (p) {
if (p->Type == MIB_IF_TYPE_ETHERNET) {
sprintfAddr(buf, p->Address, p->AddressLength);
found = 1;
if (verbose)
printf("%s: ", p->Description);
}
p = p->Next;
}
GlobalFree(pai);
return found;
}
void
sprintfAddr(LPSTR buf, const LPBYTE Address, int nAddrLen)
{
LPSTR p = buf;
for (int n = 0; n < nAddrLen; n++) {
p += sprintf(p, (n && !(n%2) ? "-%02x" : "%02x"), Address[n]);
}
}
The problem is that for your purpose, a separate win32 program is bad news: you don't want to make it easy for a customer to spoof the address. Otherwise, they could buy one license for one machine, and then clone this to as many other machines as they want.
|
|
|
RE: how to get mac address - Nov. 8, '05, 11:42:23 AM
|
|
|
asfoster
Posts: 34
Joined: Oct. 18, '05,
From: Lincolnshire UK
Status: offline
|
This is very helpful and interesting. I guess that if a win32 mini-app is the way to go then some kind of internal CRC check will be required to ensure that the program has not been replaced by a dummy.
|
|
|
RE: how to get mac address - Nov. 8, '05, 11:52:29 AM
|
|
|
jsnively
Posts: 17
Joined: Dec. 7, '03,
From: Columbus, Ohio
Status: offline
|
We implemented a challenge-response protocol: the interix program invoking the win32 "chkhost" program passes it a short random "challenge" string. The win32 program passes back, along with its response, an encrypted "answer" to the string. The interix program decrypts the "answer" and validates it against the challenge string, the mac address, the phase of the moon, etc. Not at all fun.
Worse, we have to put in a timeout, to forestall man-in-the-middle attacks (where a dishonest user puts their own "chkhost" in place, which turns around and talks to a "real" chkhost on a validly licensed machine). When the machine is heavily loaded, the timeout inappropriately kicks in.
SOOO much easier if MS would support querying the mac address from within interix, but we've had no success getting them to do this.
|
|
|
RE: how to get mac address - Nov. 8, '05, 12:18:06 PM
|
|
|
asfoster
Posts: 34
Joined: Oct. 18, '05,
From: Lincolnshire UK
Status: offline
|
I agree that it would be much easier to have a gethostid() equivalent call in Interix. However, I think a form of checksum (or CRC) of the mini-app by the calling app should make the system difficult to hack and relatively easy to put together.
|
|
|
RE: how to get mac address - Nov. 8, '05, 1:23:58 PM
|
|
|
Rodney
Posts: 3142
Joined: Jul. 9, '02,
From: /Tools lab
Status: online
|
> I presume the Registry API is a win32 API - is it exposed to interix or is there a posix API?
The registry API is an Interix API.
With it you can read the registry but you can't write to it.
The problem with MAC's is they are not always in the registry.
Lots of other things can be grokked out of the registry and provided in a Unix API manner.
With SUA (Interix 5.2 on W2K3/R2) a program can be compiled in "mixed-mode" (Interix and Win32 API's)
which would work around the problems described above.
|
|
|
RE: how to get mac address - Nov. 9, '05, 3:28:14 AM
|
|
|
asfoster
Posts: 34
Joined: Oct. 18, '05,
From: Lincolnshire UK
Status: offline
|
This sounds interesting. Do you have any examples of mixed mode complilation - does this mean that an Interix app can actually call win32 functions? You mention W2K3 R2, I am running on XP pro 2002 SP2 with latest (I think) SFU install.
Also what is the Interix registry API? I have looked through the documentation but could not find anything obvious.
|
|
|
RE: how to get mac address - Nov. 9, '05, 12:18:00 PM
|
|
|
Rodney
Posts: 3142
Joined: Jul. 9, '02,
From: /Tools lab
Status: online
|
The mixed mode compilation is with Interix 5.2 only and only on W2K3/R2 server (which
is currently at RC1 with scheduled release December or January). It can't be done
with Interix 3.5. Mixed mode is a program where Win32 and Interix API's can be mixed.
Technically the binary is a Win32 binary that can call to the Interix subsystem.
The registry API has no manual pages. The only documentation is the header files in
/usr/include/interix/{interix,registry}.h
|
|
|
RE: how to get mac address - Nov. 9, '05, 1:50:22 PM
|
|
|
markfunk
Posts: 629
Joined: Mar. 31, '03,
Status: offline
|
quote:
what is the Interix registry API?
Look for the getreg() routine in /usr/include/interix/interix.h.
quote:
GetAdaptersInfo
This is s Win32 routine in a Win32 dll.
If we could find the equivalent call in one of the NT dlls, (the DDK library?)
then we could use that and link it directly into the Interix app.
|
|
|
New Messages |
No New Messages |
Hot Topic w/ New Messages |
Hot Topic w/o New Messages |
|
Locked w/ New Messages |
Locked w/o New Messages |
|
Post New Thread
Reply to Message
Post New Poll
Submit Vote
Delete My Own Post
Delete My Own Thread
Rate Posts |
|
|
|