Página 1 de 1

MacAddress da placa de rede

Enviado: 23 Set 2014 19:26
por cl@udio
Boa noite
Gostaria de saber se existe alguma no Harbour que retorne o mac address da placa de rede e se funciona Windows e Linux.
Obrigado.

MacAddress da placa de rede

Enviado: 23 Set 2014 21:06
por Itamar M. Lins Jr.
Ola!
Alguma ? existe!

Código: Selecionar todos

*-----------------------------
PROCEDURE Main
*-----------------------------
	getMacAddress()
	
RETURN

*-----------------------------
FUNCTION getMacAddress()
*-----------------------------
	Local oWmi := WmiService(), oAdapter, ii := 0 

	for each oAdapter in oWmi:ExecQuery("Select * from Win32_NetworkAdapter where physicaladapter=true") 
		if !empty(oAdapter:MACAddress)
			++ii
			? str(ii,2,0)+ '. ' + ' Interface : ' + oAdapter:description
			? space(4)          + 'MACAddress : ' + oAdapter:MACAddress
			?
		endif
	next

	oWMI := Nil
	
Return Nil 

*-----------------------------
FUNCTION WMIService()
*-----------------------------
	local oWMI, oLocator

	oLocator   := win_oleCreateObject( "wbemScripting.SwbemLocator" )
	oWMI       := oLocator:ConnectServer()

Return oWMI

Please complile with -lhbwin (hbwin library).

Evangelos
Linux

Código: Selecionar todos

for Linux!, harbour can do:
HB_INETIFINFO()[nNic][8]

ẃhere:
nNic is number of NIC interface.
As we have in Linux as first interface often this virtual 'loopback', try '2'.
Build around a check for len of returned 2dim array.
And this '8' stands for HB_SOCKET_IFINFO_HWADDR

may look changelog for info about other elements...

best regards
Rolf
Pesquise no forum que tem mais respostas p/ essa pergunta.

Saudações,
Itamar M. Lins Jr.