Mac address how to get it ?
Posted: Mon Feb 28, 2005 3:56 am
How can I get the mac address of another pc (in lan) with code?.
http://www.purebasic.com
https://www.purebasic.fr/english/
Code: Select all
' this should be saved as a VBScript file (filename.vbs)
strComputer = "."
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\CIMV2")
wmisql = "SELECT Description,MACAddress FROM Win32_NetworkAdapterConfiguration"
Set colItems = objWMIService.ExecQuery(wmisql,"WQL")
For Each objItem In colItems
WScript.Echo "Desc: " & objItem.Description & " MACAddress: " & objItem.MACAddress
next
Code: Select all
debug SRGetMACID(ip$)
Code: Select all
; http://msdn.microsoft.com/library/en-us/iphlp/iphlp/sendarp.asp
;DWORD SendARP(
; IPAddr DestIP,
; IPAddr SrcIP,
; PULONG pMacAddr,
; PULONG PhyAddrLen
;);
;
Procedure.l GetNetworkComputerIP(computer$)
; Originally posted by Hi-Toro
; Posted: Sun Feb 16, 2003 8:27 pm
; http://forums.purebasic.com/english/viewtopic.php?t=5151
; modified on 1.3.2005 by ABBKlaus
If computer$
; Create WSA version number (damn, ugly!)...
high.b = 1: low.b = 1
DefType.w wsaversion
PokeB (@wsaversion, high) ; Gotta poke major version number into low byte...
PokeB (@wsaversion + 1, low) ; ... and minor version number into high byte
If WSAStartup_ (wsaversion, wsa.WSAData) = #NOERROR ; Try to access Windows sockets stuff...
*host.HOSTENTSTRU = gethostbyname_ (computer$) ; Get host information for named computer...
If *host <> #NULL
ip = PeekL(PeekL (*host\h_list))
ips$ = PeekS (inet_ntoa_ (PeekL(PeekL (*host\h_list)))) ; Get IP address of named computer...
EndIf
WSACleanup_ () ; Close Windows sockets stuff...
EndIf
ProcedureReturn ip
EndIf
EndProcedure
Procedure.s GetComputerName()
buffer.s=Space(64)
bufsize.l=64
GetComputerName_(@buffer, @bufsize)
ProcedureReturn buffer
EndProcedure
Procedure.s MacToString(*membuffer)
MAC$=""
For i=0 To 5
MAC$+RSet(Hex(PeekB(*membuffer+i)&$FF),2,"0")
If i<5
MAC$+":"
EndIf
Next
ProcedureReturn MAC$
EndProcedure
ip=GetNetworkComputerIP("DEM041452") ; Fill in the desired Computername
thisip=GetNetworkComputerIP(GetComputerName())
Debug "This IP="+IPString(thisip)
maclen=6
*buffer=AllocateMemory(8)
If SendARP_(ip,thisip,*buffer,@maclen)=#NO_ERROR
Debug "SendARP to IP="+IPString(ip)+" Success"
Debug MacToString(*buffer)
Else
Debug "SendARP to IP="+IPString(ip)+" Failed"
EndIf
FreeMemory(*buffer)
Hi-Toro is the original author AFAIK...ABBKlaus wrote: PS: the GetNetworkComputerIP(computer$) routine is not mineand i don´t know the author
Code: Select all
; http://msdn.microsoft.com/library/en-us/iphlp/iphlp/sendarp.asp
;DWORD SendARP(
; IPAddr DestIP,
; IPAddr SrcIP,
; PULONG pMacAddr,
; PULONG PhyAddrLen
;);
;
Procedure.l GetNetworkComputerIP(computer$)
; Originally posted by Hi-Toro
; Posted: Sun Feb 16, 2003 8:27 pm
; http://forums.purebasic.com/english/viewtopic.php?t=5151
; modified on 1.3.2005 by ABBKlaus
; made PB4.0 compatible on 19.5.2006 by ABBKlaus
If computer$
; Create WSA version number (damn, ugly!)...
high.b = 1: low.b = 1
wsaversion.w
PokeB (@wsaversion, high) ; Gotta poke major version number into low byte...
PokeB (@wsaversion + 1, low) ; ... and minor version number into high byte
If WSAStartup_ (wsaversion, wsa.WSAData) = #NOERROR ; Try to access Windows sockets stuff...
*host.HOSTENT = gethostbyname_ (computer$) ; Get host information for named computer...
If *host <> #Null
ip = PeekL(PeekL (*host\h_addr_list))
ips$ = PeekS (inet_ntoa_ (PeekL(PeekL (*host\h_addr_list)))) ; Get IP address of named computer...
EndIf
WSACleanup_ () ; Close Windows sockets stuff...
EndIf
ProcedureReturn ip
EndIf
EndProcedure
Procedure.s GetComputerName()
buffer.s=Space(64)
bufsize.l=64
GetComputerName_(@buffer, @bufsize)
ProcedureReturn buffer
EndProcedure
Procedure.s MacToString(*membuffer)
MAC$=""
For i=0 To 5
MAC$+RSet(Hex(PeekB(*membuffer+i)&$FF),2,"0")
If i<5
MAC$+":"
EndIf
Next
ProcedureReturn MAC$
EndProcedure
ip=GetNetworkComputerIP("KLAUS-AMD") ; Fill in the desired Computername
thisip=GetNetworkComputerIP(GetComputerName())
Debug "This IP="+IPString(thisip)
maclen=6
*buffer=AllocateMemory(8)
If SendARP_(ip,thisip,*buffer,@maclen)=#NO_ERROR
Debug "SendARP to IP="+IPString(ip)+" Success"
Debug MacToString(*buffer)
Else
Debug "SendARP to IP="+IPString(ip)+" Failed"
EndIf
FreeMemory(*buffer)
Code: Select all
Procedure.s GetIpAddr(ComputerName.s)
If ComputerName
If WSAStartup_ ((1<<8|1), wsa.WSADATA) = #NOERROR
*host.HOSTENT = gethostbyname_(ComputerName)
WSACleanup_()
If *host
ProcedureReturn PeekS(inet_ntoa_(PeekL(PeekL(*host\h_addr_list))))
EndIf
EndIf
EndIf
EndProcedure
Procedure.s GetMacAddr(IP.s)
n.l = 6
Dim MacAddr.b(n)
If SendARP_(inet_addr_(IP), 0, @MacAddr(0), @n) = #NO_ERROR
For i = 0 To n - 2
MAC$ + RSet(Hex(MacAddr(i)&255),2,"0") + ":"
Next
ProcedureReturn MAC$ + RSet(Hex(MacAddr(i)&255),2,"0")
EndIf
EndProcedure
Procedure.s GetHostName()
Size.l = 32
Host.s = Space(Size)
GetComputerName_(@Host, @Size)
ProcedureReturn Host
EndProcedure
Debug GetHostName()
Debug GetIpAddr(GetHostName())
Debug GetMacAddr(GetIpAddr(GetHostName()))