Network Card Mac Address

S

Sid Knee

I need to obtain the mac-address for my network card in the form of a
string which I can use in a BASIC program.

Currently I've done this by running ipconfig /all >mac.txt and then
having the BASIC program open the file mac.txt and dig out the mac
address from its contents.

Seems real clumsy. Is the mac address available in the form of a
parameter, environment variable etc that the program could get more
directly from the system?
 
J

Jim Howes

Sid said:
Seems real clumsy. Is the mac address available in the form of a
parameter, environment variable etc that the program could get more
directly from the system?

I have some C code that gets the MAC addresses of each interface on the system,
I've wrapped it up in a simple main() which just prints it out.

It uses the Netbios() function to first count the number of interfaces with a
NCBENUM command, and then for each interface, uses Netbios() with NCBRESET and
NCBASTAT commands to get the adapter status.
It then copies the MAC address out of the ASTAT structure (.adapt.adapter_address)

If you can mangle that C into appropriate basic (A language that I absolutely
refuse to even consider doing for you), you can grab the code from
www.jimhowes.org.uk/getmac.c
(Code supplied with no warranty - If it breaks you get to keep both pieces, etc.)

If this is successful, please post the basic code to save others the same job.

Jim
 
J

Jerold Schulman

I need to obtain the mac-address for my network card in the form of a
string which I can use in a BASIC program.

Currently I've done this by running ipconfig /all >mac.txt and then
having the BASIC program open the file mac.txt and dig out the mac
address from its contents.

Seems real clumsy. Is the mac address available in the form of a
parameter, environment variable etc that the program could get more
directly from the system?

Pass it as a parameter:

for /f "Tokens=2 Delims=:" %a in ('ipconfig /all^|find "Physical Address"') do YourBASICprogram%a

Jerold Schulman
Windows Server MVP
JSI, Inc.
http://www.jsiinc.com
http://www.jsifaq.com
 
S

Sid Knee

Jim said:
If you can mangle that C into appropriate basic (A language that I absolutely
refuse to even consider doing for you), you can grab the code from
www.jimhowes.org.uk/getmac.c

No guarantees (by no possible stretch of the imagination could I
describe myself as a programmer in any normal interpretation of the word
- it's why I use BASIC) but I'll certainly give it a look and see if I
can stumble on something. Or perhaps bribe/blackmail a friend for some help.

Thanks a bunch, Jim.

:)
 
S

Sid Knee

Jerold said:
Pass it as a parameter:

for /f "Tokens=2 Delims=:" %a in ('ipconfig /all^|find "Physical Address"') do YourBASICprogram%a

Thanks, Jerold. It might take me some time to figure out exactly what is
going on there. I take it that the string is passed in "Physical Address"?
 
S

Sid Knee

Sid said:
Thanks, Jerold. It might take me some time to figure out exactly what is
going on there. I take it that the string is passed in "Physical Address"?

Scratch that, I follow ... thanks
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top