MAC address From Dos

Question about which tools to use, bugs, the best way to implement a function, etc should go here. Don't forget to see if your question is answered in the wiki first! When in doubt post here.
Post Reply
chaand

MAC address From Dos

Post by chaand »

hai all,
how we can get the MAC address of NIC card from pure DOS.
i need C or C++ or Assembly program to find the MAC address.
bye
chaand
carbonBased

RE:MAC address From Dos

Post by carbonBased »

I would imagine this would be different for each brand of network card, and yes, I would imagine some ammount of assembly would be required.

Not much of an answer, I know, but I don't believe there is just _one_ answer.

Cheers,
Jeff
chaand

RE:MAC address From Dos

Post by chaand »

Dear Jeff,

yes, i find an interrupt to get the mac address. but it is not working
the interrupt is 0x60
and ah = 6
and cx = 6
es:di seg and offset of an unsigned char's arrary of 6 size

but this not working

do you know something more about this

regards,

chaand
chaand

RE:MAC address From Dos

Post by chaand »

Hello i got the answer form the following c program provided netbios interface is loaded into your dos machine

/*
GETMAC.C
--------
A small program for determining the Network Adapter ID using
the NetBIOS interface.

Coded by Dzu Trinh Dac Nguyen
*/

#include <dos.h>
#include <string.h>
#include <mem.h>
#include <stdio.h>

typedef unsigned char BYTE;
typedef unsigned int WORD;
typedef int BOOL;
#define FALSE 0
#define TRUE 1

typedef struct tagNCB
{
BYTE NCB_COMMAND;
BYTE NCB_RETCODE;
BYTE NCB_LSN;
BYTE NCB_NUM;

void far * NCB_BUFFER_PTR;

WORD NCB_LENGTH;
BYTE NCB_CALLNAME[16];
BYTE NCB_NAME[16];
BYTE NCB_RTO;
BYTE NCB_STO;

void interrupt ( * postfunc)(void);
BYTE NCB_LANA_NUM;
BYTE NCB_CMD_CPLT;
BYTE NCB_RESERVED[14];
} NCB;

typedef struct tagNAME_TABLE
{
char tbl_name[16];
BYTE tbl_name_number;
        BYTE tbl_name_status;
} NAME_TABLE;

typedef struct tagADAPTER_STATUS
{
BYTE card_id[6];
BYTE unknown[52];
int name_count;
NAME_TABLE      name_table[20];
} ADAPTER_STATUS;

BYTE   NETBIOS(NCB far * ncb)
{
struct SREGS sr;
union REGS r;

sr.es = FP_SEG(ncb);
r.x.bx = FP_OFF(ncb);
r.x.ax = 0x0100;
int86x(0x5C, &r, &r, &sr);
return ncb->NCB_CMD_CPLT;
}

BOOL netbiosInstalled()
{
NCB test_ncb;
void interrupt ( * test)(void);

test = _dos_getvect(0x5C);
if (test == (void far *) NULL)
return FALSE;

memset(&test_ncb, 0, sizeof(NCB));
test_ncb.NCB_COMMAND = 0x7F;
NETBIOS(&test_ncb);

if (test_ncb.NCB_RETCODE != 0x03)
return FALSE;

return TRUE;
}

BYTE netbiosGetAdapterStatus(char far * buffer, int len)
{
NCB ncb;
memset(&ncb, 0, sizeof(NCB));
strcpy(ncb.NCB_CALLNAME, "*");
ncb.NCB_COMMAND = 0x33;
ncb.NCB_LENGTH = len;
ncb.NCB_BUFFER_PTR = buffer;
return NETBIOS(&ncb);
}

void main(void)
{
ADAPTER_STATUS as;

if (netbiosInstalled())
{
if (0 == netbiosGetAdapterStatus((char far *) &as, sizeof(ADAPTER_STATUS)))
{
printf( "Adapter ID: %02X.%02X.%02X.%02X.%02X.%02X\n",
as.card_id[0], as.card_id[1], as.card_id[2],
as.card_id[3], as.card_id[4], as.card_id[5]);
}
else
printf("Error reading the network adapter address.\n");
}
else
printf("NetBIOS is not installed.\n");
}
Post Reply