2024年3月13日发(作者:)

方法一:nbtstat 命令

Public Function GetMac(ByVal IP As String) As String

Try

'定义输出变量。

Dim StrMac As String =

Dim Str As String =

'定义进程参数。

Dim Info As New ProcessStartInfo

me = ";nbtstat";

nts = ";-a "; + IP

llExecute = False

ctStandardInput = False

ctStandardOutput = True

ctStandardError = True

NoWindow = True

Style =

'定义新进程。

Dim mProcess As New Process

'开始执行操作。

mProcess = (Info)

'无限循环按行读取输出内容。

While True

'读取一行数据。

Str = ne()

rExit()

StrMac = ()

'判断是否有 Mac Address字眼。

If ns(";mac address";) Then

Exit While

Else

If ns(";host not found";) Then

Exit While

End If

End If

End While

'返回值。

Return StrMac

Catch ex As Exception

'返回错误值。

Return (";Get Error. 原因:{0}";, e)

End Try

方法2:SendARP 函数

Private Declare Ansi Function SendARP Lib ";"; (ByVal dest As Int32,

ByVal host As Int32, ByRef mac As Int64, ByRef length As Int32) As Int32

Private Declare Ansi Function inet_addr Lib ";Ws2_"; (ByVal IP As String) As

Int32

Public Function getRemoteMAC(ByVal RemoteIp As String) As String

Dim Dest As Int32 = inet_addr(RemoteIp)

Dim Str As String =

Dim StrMac As String =

Try

Dim MacInfo As New Int64

Dim Len As Int32 = 6

Dim Res As Integer = SendARP(Dest, 0, MacInfo, Len)

Str = ng(MacInfo, 16).ToUpper

If = 12 Then

'因为取出来的值是反的,所以要处理下。

Dim M(5) As String

M(0) = ing(10, 2)

M(1) = ing(8, 2)

M(2) = ing(6, 2)

M(3) = ing(4, 2)

M(4) = ing(2, 2)

M(5) = ing(0, 2)

StrMac = (";{0}-{1}-{2}-{3}-{4}-{5}";, M(0), M(1), M(2), M(3), M(4),

M(5))

Else

StrMac = ";Host not found.";

End If

Catch ex As Exception

'返回错误值。

Return (";Get Error. 原因:{0}";, e)

End Try

Return StrMac

End Function

方法3:用WMI,先工程-引用 Microsoft WMI Scripting V1.1 Library

Private Sub wmiSoundDeviceInfo()

Dim wmiObjSet As bjectSet

Dim obj As SWbemObject

wmiObjSet = GetObject(";winmgmts:{impersonationLevel=impersonate}";). _

InstancesOf(";Win32_NetworkAdapterConfiguration";)

For Each obj In wmiObjSet

(ress)

Next

End Sub

方法4:

Imports kInformation

Function getMacAddress()

Dim nics() As NetworkInterface = _

NetworkInterfaces

Return nics(0).ng

End Function