Mac address how to get it ?
Mac address how to get it ?
How can I get the mac address of another pc (in lan) with code?.
I would use WMI to get information from another PC. Here is an example of how to get the MAC address from the local PC using WMI.
It should work on a remote PC but I have not tried it.
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
-Beach
You could use Ring's SRGETINFO userlib available at : http://www.purearea.net/pb/english/index.htm
like so :
like so :
Code: Select all
debug SRGetMACID(ip$)
or you could follow this link viewtopic.php?t=10839&highlight=
ok then try this out :
PS: the GetNetworkComputerIP(computer$) routine is not mine
and i don´t know the author (fixed
)
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)


Last edited by ABBKlaus on Tue Mar 01, 2005 10:21 am, edited 1 time in total.
Hi-Toro is the original author AFAIK...ABBKlaus wrote: PS: the GetNetworkComputerIP(computer$) routine is not mineand i don´t know the author
viewtopic.php?t=5151
Good programmers don't comment their code. It was hard to write, should be hard to read.
- Psychophanta
- Always Here
- Posts: 5153
- Joined: Wed Jun 11, 2003 9:33 pm
- Location: Anare
- Contact:
Thats easy

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)
- Psychophanta
- Always Here
- Posts: 5153
- Joined: Wed Jun 11, 2003 9:33 pm
- Location: Anare
- Contact:
a variant :
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()))
Last edited by Flype on Sat May 20, 2006 12:06 pm, edited 1 time in total.
No programming language is perfect. There is not even a single best language.
There are only languages well suited or perhaps poorly suited for particular purposes. Herbert Mayer
There are only languages well suited or perhaps poorly suited for particular purposes. Herbert Mayer