Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
How to retrieve a NIC Mac Address and its IP
Message
Information générale
Forum:
Visual FoxPro
Catégorie:
Fonctions Windows API
Versions des environnements
Visual FoxPro:
VFP 7
OS:
Windows XP SP2
Network:
Windows 2003 Server
Database:
Visual FoxPro
Divers
Thread ID:
00996178
Message ID:
00996542
Vues:
25
Adjusted to show information for multiple network interfaces
* 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 j,lcNICStr, lcNICName, lnAddrlen, lcAddress, ii, lcIntraIP, lcMask, lcGateway

FOR j=1 TO len(lcBuffer) STEP 640
  lcNICStr = substr(lcBuffer,J,640)
  * lcNICName is between {}
  lcNICName = STREXTRACT(lcNICStr,"{","}",1)
  * 401st byte of lcNICStr is size of NIC address string
  lnAddrlen = Asc(SUBSTR(lcNICStr, 401, 1)) 
  * actual NIC address starts at byte 405 of lcNICStr
  lcAddress = SUBSTR(lcNICStr, 405, lnAddrlen) 
  lcIntraIP = SUBSTR(lcNICStr,433,15)
  lcIntraIP = LEFT(lcIntraIP,at(chr(0),lcIntraIP)-1)
  lcMask = SUBSTR(lcNICStr,449,15)
  lcMask = LEFT(lcMask,at(chr(0),lcMask)-1)
  lcGateway = SUBSTR(lcNICStr,473,15)
  lcGateway = LEFT(lcGateway,at(chr(0),lcGateway)-1)

  * 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 Name (chr)  : '+lcNICName
  ? 'NIC ID (decimal): '+lcThisID
  ? 'NIC ID (hex)    : '+ lcThisHex 
  ? 'NIC IntraIP     : '+ lcIntraIP
  ? 'NIC Mask        : '+ lcMask
  ? 'NIC Gateway     : '+ lcGateway
NEXT

Clear DLLS GetAdaptersInfo

Just an opinion... Not a fact.
Précédent
Répondre
Fil
Voir

Click here to load this message in the networking platform