通過IP獲取MAC位址

2021-05-26 16:49:09 字數 2740 閱讀 2005

option explicit

private declare function openprocess lib "kernel32" (byval _

dwdesiredaccess as long, byval binherithandle as long, _

byval dwprocessid as long) as long

private declare function waitforsingleobject lib "kernel32" _

(byval hhandle as long, byval dwmilliseconds as long) _

as long

private const infinite = -1&

private const synchronize = &h100000

private declare function inet_addr lib "wsock32.dll" (byval s as string) as long

private declare function sendarp lib "iphlpapi.dll" (byval destip as long, byval srcip as long, pmacaddr as long, phyaddrlen as long) as long

private declare sub copymemory1 lib "kernel32" alias "rtlmovememory" (dst as any, src as any, byval bcount as long)

public function getremotemacaddress(byval sremoteip as string)

dim dwremoteip     as long

dim pmacaddr     as long

dim bpmacaddr()     as byte

dim phyaddrlen     as long

dim cnt     as long

dim tmp     as string

'convert    the    string    ip    into

'an    unsigned    long    value    containing

'a    suitable    binary    representation

'of    the    internet    address    given

dwremoteip = inet_addr(sremoteip)

if dwremoteip <> 0 then

'set    phyaddrlen    to    6

phyaddrlen = 6

'retrieve    the    remote    mac    address

on error resume next

if sendarp(dwremoteip, 0&, pmacaddr, phyaddrlen) = 0 then

'getremotemacaddress = pmacaddr

'exit function

if pmacaddr <> 0 and phyaddrlen <> 0 then

'returned    value    is    a    long    pointer

'to    the    mac    address,    so    copy    data

'to    a    byte    array

redim bpmacaddr(0 to phyaddrlen - 1)

copymemory1 bpmacaddr(0), pmacaddr, byval phyaddrlen

'loop    through    array    to    build    string

for cnt = 0 to phyaddrlen - 1

if bpmacaddr(cnt) = 0 then

tmp = tmp & "00-"

else

if len(hex$(bpmacaddr(cnt))) = 1 then

tmp = tmp & "0" & hex$(bpmacaddr(cnt)) & "-"

else

tmp = tmp & hex$(bpmacaddr(cnt)) & "-"

end if

end if

next

'remove    the    trailing    dash

'added    above    and    return    true

if len(tmp) > 0 then

'sremotemacaddress = left$(tmp, len(tmp) - 1)

getremotemacaddress = left$(tmp, len(tmp) - 1)

end if

exit function

else

getremotemacaddress = false

end if

else

getremotemacaddress = false

end if       'sendarp

else

getremotemacaddress = false

end if       'dwremoteip

end function

通過vbs獲取本機IP位址和MAC位址

1,定義函式 function getipmac computername dim objwmiservice,colitems,objitem,objaddress set objwmiservice getobject winmgmts computername root cimv2 set c...

delphi 實現通過ip位址獲取mac位址

function sendarp ipaddr ulong temp dword ulmacaddr pointer ulmacaddrleng pointer dword stdcall external iphlpapi.dll name sendarp function getmacbyip ...

android獲取Mac位址和IP位址

獲取mac位址實際專案中測試了如下幾種方法 1 裝置開通wifi連線,獲取到網絡卡的mac位址 但是不開通wifi,這種方法獲取不到mac位址,這種方法也是網路上使用的最多的方法 根據wifi資訊獲取本地mac public static string getlocalmacaddressfromw...