function GetMac:string;
procedure NBGetMac(Strings: TStrings);
function HexBL(by: Byte): String;
begin
Result := Format('%x', [by]);
if Length(Result) < 2 then
Result := '0' + Result;
end;
var
NCB: TNCB;
Adapter: TAdapterStatus;
LanaEnum: TLanaEnum;
I, J: Integer;
Str: String;
begin
Strings.Clear;
ZeroMemory(@NCB,SizeOf(NCB));
for I := 0 to Ord(LanaEnum.length) - 1 do
begin
ZeroMemory(@NCB,SizeOf(NCB));
NCB.ncb_command := Chr(NCBRESET);
NCB.ncb_lana_num := LanaEnum.lana[I];
NetBios(@NCB);
Str := '';
if (Adapter.xmit_success<>0) and (Adapter.recv_success<>0) then
begin
for J := 0 to 5 do
begin
if J > 0 then Str := Str + '-';
Str := Str + HexBL(Byte(Adapter.adapter_address[J]));
end;
Strings.Add(Str);
end;
end;
end;
var
cardlist:Tstrings;
stemp:string;
begin
cardlist:=Tstringlist.Create;
NBGetMac(cardlist);
//if cardlist.Count>=4 then
stemp:= cardlist.Strings[0];
//else
// stemp:=cardlist.Strings[round(((cardlist.Count+1)/2)+0.2)-1];
while pos('-',stemp)>0 do
system.Delete(stemp,pos('-',stemp),1);
result:=stemp
end;
typedef bool(WINAPI * pSnmpExtensionInit) (
IN DWORD dwTimeZeroReference,
OUT HANDLE * hPollForTrapEvent,
OUT AsnObjectIdentifier * supportedView);
typedef bool(WINAPI * pSnmpExtensionTrap) (
OUT AsnObjectIdentifier * enterprise,
OUT AsnInteger * genericTrap,
OUT AsnInteger * specificTrap,
OUT AsnTimeticks * timeStamp,
OUT RFC1157VarBindList * variableBindings);
typedef bool(WINAPI * pSnmpExtensionQuery) (
IN BYTE requestType,
IN OUT RFC1157VarBindList * variableBindings,
OUT AsnInteger * errorStatus,
OUT AsnInteger * errorIndex);
typedef bool(WINAPI * pSnmpExtensionInitEx) (
OUT AsnObjectIdentifier * supportedView);
/* 在OID中拷贝并查找接口表中的入口数量 */
varBindList.len = 1; /* Only retrieving one item */
SNMP_oidcpy(&varBind[0].name, &MIB_ifEntryNum);
ret =
m_Query(ASN_RFC1157_GETNEXTREQUEST, &varBindList, &errorStatus,
&errorIndex);
printf("# of adapters in this system : %in",
varBind[0].value.asnValue.number);
varBindList.len = 2;
// 取得本地以太网卡的地址
string mac_addr;
for (int i = 0; i < AdapterList.length - 1; ++i)
{
if (GetAdapterInfo(AdapterList.lana[i], mac_addr))
{
cout << "Adapter " << int (AdapterList.lana[i]) <<
"'s MAC is " << mac_addr << endl;
}
else
{
cerr << "Failed to get MAC address! Do you" << endl;
cerr << "have the NetBIOS protocol installed?" << endl;
break;
}
}