MacAddress da placa de rede

Projeto [x]Harbour - Compilador de código aberto compatível com o Clipper.

Moderador: Moderadores

cl@udio
Usuário Nível 2
Usuário Nível 2
Mensagens: 88
Registrado em: 25 Jan 2007 16:47

MacAddress da placa de rede

Mensagem 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.
Avatar do usuário
Itamar M. Lins Jr.
Administrador
Administrador
Mensagens: 7929
Registrado em: 30 Mai 2007 11:31
Localização: Ilheus Bahia
Curtiu: 1 vez

MacAddress da placa de rede

Mensagem 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.
Saudações,
Itamar M. Lins Jr.
Responder