获取本机的Mac地址(.net vb)

来源:互联网 发布:js设置input为必填 编辑:程序博客网 时间:2024/04/28 00:41

Public Function GetMac(ByVal IP As String) As String
        Dim str1 As String = String.Empty
        Try
            Dim str2 As String = String.Empty
            Dim info1 As ProcessStartInfo = New ProcessStartInfo
            Dim process1 As Process = New Process

            info1.FileName = "nbtstat"
            info1.RedirectStandardInput = False
            info1.RedirectStandardOutput = True
            info1.Arguments = "-A " + IP
            info1.UseShellExecute = False
            process1 = Process.Start(info1)

            Dim num1 As Integer = -1

            While (num1 <= -1)
                num1 = str2.Trim().ToLower().IndexOf("mac address", 0)
                If (num1 > -1) Then
                    Exit While
                End If

                str2 = process1.StandardOutput.ReadLine()
                process1.WaitForExit()
                str1 = str2.Trim()
            End While
        Catch ex As Exception
            Throw ex
        End Try


        Return str1
    End Function

原创粉丝点击