发信人: hotpc(不回头) 
整理人: foxzz(2004-12-28 08:54:12), 站内信件
 | 
 
 
* 大家都在找,不贴出来就不好意思了
 
 * GetNicID - uses Win-32 API call to get NIC ID (physical address)
 
 * this is the DLL declaration to access the API method
 DECLARE INTEGER GetAdaptersInfo IN iphlpapi ; 
     STRING @pAdapterInfo, LONG @pOutBufLen 
 
 LOCAL lcBuffer, lnBufsize 
 lnBufsize = 0 
 lcBuffer = "" 
 
 * first call to GetAdaptorsInfo() method
 * this call usually returns: ERROR_BUFFER_OVERFLOW (111)
 * with lnBufsize set to the required amount of memory 
 = GetAdaptersInfo(@lcBuffer, @lnBufsize) 
 
 * build buffer string from nulls
 lcBuffer = Repli(Chr(0), lnBufsize) 
 
 * call method again
 IF GetAdaptersInfo(@lcBuffer, @lnBufsize) <> 0 && ERROR_SUCCESS 
   * no joy 
   =MESSAGEBOX('WinAPI problem - GetAdaptorsInfo')
   RETURN 
 ENDIF 
 
 LOCAL lnAddrlen, lcAddress, ii
 * 401st byte of lcBuffer is size of NIC address string
 lnAddrlen = Asc(SUBSTR(lcBuffer, 401, 1)) 
 * actual NIC address starts at byte 405 of lcBuffer
 lcAddress = SUBSTR(lcBuffer, 405, lnAddrlen) 
 
 * build decimal and hex strings from ASCII values of returned characters
 lcThisID = ''
 lcThisHex = ''
 
 FOR ii = 1 TO lnAddrLen
 	lcThisID = lcThisID + ;
 	IIF(ii>1,',','') + ;
 	ALLTRIM(STR(ASC(SUBSTR(lcAddress,ii,1))))
 	
 	lcThisHex = lcThisHex + ;
 	IIF(ii>1,'-','') + ;
 	RIGHT(TRANSFORM(ASC(SUBSTR(lcAddress,ii,1)),'@0'),2)
 NEXT 
 
 * display decimal and hex versions of NIC ID
 ?
 ? 'NIC ID (decimal): '+lcThisID
 ? 'NIC ID (hex): '+ lcThisHex | 
 
 
 |