Thread View: borland.public.cppbuilder.internet.socket
3 messages
3 total messages
Started by Richard
Tue, 24 Aug 2004 10:07
Using SNMP to extract the MAC Address in Builder 6
Author: Richard
Date: Tue, 24 Aug 2004 10:07
Date: Tue, 24 Aug 2004 10:07
6 lines
1320 bytes
1320 bytes
In the article http://bdn.borland.com/article/0,1410,26040,00.html 3 methods of how to obtain the MAC addresses of NICs are described. The third method uses SNMP and seems to work perfectly with Builder 5, but I cannot get it to work with Builder 6. The program compiles and runs, but does not report any NICs present. Exceptions are also thrown as the routine crashes due to no NICs. Any help would be greatly appreciated. Thanks, Richard
Re: Using SNMP to extract the MAC Address in Builder 6
Author: Mark Jacobs
Date: Tue, 24 Aug 2004 10:38
Date: Tue, 24 Aug 2004 10:38
49 lines
2413 bytes
2413 bytes
On 24 Aug 2004 03:07:02 -0700, Richard <Richard.Gallois@footfall.com>
wrote:
> In the article http://bdn.borland.com/article/0,1410,26040,00.html 3
> methods of how to obtain the MAC addresses of NICs are
> described. The third method uses SNMP and seems to work perfectly with
> Builder 5, but I cannot get it to work with Builder 6. The
> program compiles and runs, but does not report any NICs present.
> Exceptions are also thrown as the routine crashes due to no NICs.
AnsiString mjgetnicinfo()
{
IP_ADAPTER_INFO AdapterInfo[16]; AnsiString retv=""; unsigned int ii;
DWORD dwBufLen,dwStatus;
dwBufLen=sizeof(AdapterInfo);
dwStatus=GetAdaptersInfo(AdapterInfo,&dwBufLen);
if (dwStatus!=ERROR_SUCCESS) return "**Could not Obtain NIC Info";
PIP_ADAPTER_INFO pAdapterInfo=AdapterInfo;
do
{
retv+="Name :"+AnsiString(pAdapterInfo->AdapterName)+"\r\nDescription
:"+
AnsiString(pAdapterInfo->Description)+"\r\nMAC :";
for (ii=0;ii<pAdapterInfo->AddressLength;++ii)
retv+=IntToHex(pAdapterInfo->Address[ii],2)+" ";
retv+="\r\n"; pAdapterInfo=pAdapterInfo->Next;
}
while (pAdapterInfo);
return retv;
}
Does the routine above work? Hope it helps.
--
Mark Jacobs
DK Computing
http://www.dkcomputing.co.uk
markj atty critical dotty co dotty uk
Re: Using SNMP to extract the MAC Address in Builder 6
Author: Richard
Date: Tue, 24 Aug 2004 11:14
Date: Tue, 24 Aug 2004 11:14
58 lines
2619 bytes
2619 bytes
Many thanks Mark. Your code works perfecly on BCB6/WinXP. I
was not aware of all the great functions available in
IPHLPAPI.lib. I definitely will not be playing with the
unbelievably complicated SNMP API again.
Richard
"Mark Jacobs" <markjattycriticaldottycodottyuk> wrote:
>On 24 Aug 2004 03:07:02 -0700, Richard <Richard.Gallois@footfall.com> =
>
>wrote:
>
>> In the article http://bdn.borland.com/article/0,1410,26040,00.html 3 =
>
>> methods of how to obtain the MAC addresses of NICs are
>> described. The third method uses SNMP and seems to work perfectly with=
> =
>
>> Builder 5, but I cannot get it to work with Builder 6. The
>> program compiles and runs, but does not report any NICs present. =
>
>> Exceptions are also thrown as the routine crashes due to no NICs.
>
>AnsiString mjgetnicinfo()
>{
> IP_ADAPTER_INFO AdapterInfo[16]; AnsiString retv=3D""; unsigned int i=
>i; =
>
>DWORD dwBufLen,dwStatus;
> dwBufLen=3Dsizeof(AdapterInfo); =
>
>dwStatus=3DGetAdaptersInfo(AdapterInfo,&dwBufLen);
> if (dwStatus!=3DERROR_SUCCESS) return "**Could not Obtain NIC Info";
> PIP_ADAPTER_INFO pAdapterInfo=3DAdapterInfo;
> do
> {
> retv+=3D"Name :"+AnsiString(pAdapterInfo->AdapterName)+"\r\nDescrip=
>tion =
>
>:"+
> AnsiString(pAdapterInfo->Description)+"\r\nMAC :";
> for (ii=3D0;ii<pAdapterInfo->AddressLength;++ii) =
>
>retv+=3DIntToHex(pAdapterInfo->Address[ii],2)+" ";
> retv+=3D"\r\n"; pAdapterInfo=3DpAdapterInfo->Next;
> }
> while (pAdapterInfo);
> return retv;
>}
>
>Does the routine above work? Hope it helps.
>-- =
>
>Mark Jacobs
>DK Computing
>http://www.dkcomputing.co.uk
>markj atty critical dotty co dotty uk
Thread Navigation
This is a paginated view of messages in the thread with full content displayed inline.
Messages are displayed in chronological order, with the original post highlighted in green.
Use pagination controls to navigate through all messages in large threads.
Back to All Threads