您的位置:首页 > 其它

远程客户端网卡MAC获得

2010-09-20 18:10 274 查看
Get MAC Address, SNMP Method

snmpmac.cpp


snmpapi.cpp

/******************************************************************
*
*      Copyright (C) Stas Khirman 1998.  All rights reserved.
*
*       This program is distributed WITHOUT ANY WARRANTY
*
*******************************************************************/

/*************************************************
*
*       Reproduction of SNMP.LIB and SNMPAPI.LIB base
*           functions
*
* Author: Stas Khirman (staskh@rocketmail.com)
*
*
* Free software: no warranty; use anywhere is ok; spread the
* sources; note any modifications; share variations and
* derivatives (including sending to staskh@rocketmail.com).
*
*
*************************************************/
#include <snmp.h>

SNMPAPI
SNMP_FUNC_TYPE
SnmpUtilOidCpy(
OUT AsnObjectIdentifier *DstObjId,
IN  AsnObjectIdentifier *SrcObjId
)
{
DstObjId->ids = (UINT *)GlobalAlloc(GMEM_ZEROINIT,SrcObjId->idLength *
sizeof(UINT));
if(!DstObjId->ids){
SetLastError(1);
return 0;
}

memcpy(DstObjId->ids,SrcObjId->ids,SrcObjId->idLength*sizeof(UINT));
DstObjId->idLength = SrcObjId->idLength;

return 1;
}

VOID
SNMP_FUNC_TYPE
SnmpUtilOidFree(
IN OUT AsnObjectIdentifier *ObjId
)
{
GlobalFree(ObjId->ids);
ObjId->ids = 0;
ObjId->idLength = 0;
}

SNMPAPI
SNMP_FUNC_TYPE
SnmpUtilOidNCmp(
IN AsnObjectIdentifier *ObjIdA,
IN AsnObjectIdentifier *ObjIdB,
IN UINT                 Len
)
{
UINT CmpLen;
UINT i;
int  res;

CmpLen = Len;
if(ObjIdA->idLength < CmpLen)
CmpLen = ObjIdA->idLength;
if(ObjIdB->idLength < CmpLen)
CmpLen = ObjIdB->idLength;

for(i=0;i<CmpLen;i++){
res = ObjIdA->ids[i] - ObjIdB->ids[i];
if(res!=0)
return res;
}
return 0;
}

VOID
SNMP_FUNC_TYPE
SnmpUtilVarBindFree(
IN OUT RFC1157VarBind *VarBind
)
{
BYTE asnType;
// free object name
SnmpUtilOidFree(&VarBind->name);

asnType = VarBind->value.asnType;

if(asnType==ASN_OBJECTIDENTIFIER){
SnmpUtilOidFree(&VarBind->value.asnValue.object);
}
else if(
(asnType==ASN_OCTETSTRING) ||
(asnType==ASN_RFC1155_IPADDRESS) ||
(asnType==ASN_RFC1155_OPAQUE) ||
(asnType==ASN_SEQUENCE)){
if(VarBind->value.asnValue.string.dynamic){
GlobalFree(VarBind->value.asnValue.string.stream);
}
}

VarBind->value.asnType = ASN_NULL;

}


In my search for an ironclad method of finding the MAC address of the ethernet card of a system, I attempted the NetBIOS method as described in the FAQ, but found this to be unacceptable as some of our customers reportedly didn’t use [NetBIOS]. I passed over the RPC method, and found a solution in a page maintained by Stas Khirman and Raz Galili.... They describe a method of using the internal SNMP calls in Windows (NT, 95, and 2000 have worked for me) that are used by netstat and other windows utilities, but unfortunately provide no code example for finding the MAC code.

[Below is] a small program I’ve written up, so that hopefully other people won’t have to go through the same learning curve I did with SNMP. I will also attach a file, snmpapi.cpp, that was written by Stas Khirman and distributed on his web page.

http://www.docin.com/p-23654770.html

http://tangentsoft.net/wskfaq/examples/getmac-snmp.html
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: