第一種:只拿到純數字的
'獲取物理地址
Dim strMacAddress As String = String.Empty
Dim nics() As NetworkInterface = NetworkInterface.GetAllNetworkInterfaces()
strMacAddress = nics(0).GetPhysicalAddress.ToString
第二種:中間有連接符號
'獲取物理地址
Dim macs As List(Of String) = New List(Of String)
Dim startInfo As ProcessStartInfo = New ProcessStartInfo("ipconfig", "/all")
startInfo.UseShellExecute = False
startInfo.RedirectStandardInput = True
startInfo.RedirectStandardOutput = True
startInfo.RedirectStandardError = True
startInfo.CreateNoWindow = True
Dim p As Process = Process.Start(startInfo) '截取輸出流
Dim reader As StreamReader = p.StandardOutput
Dim line As String = reader.ReadLine()
While Not reader.EndOfStream
If Not IsNothing(line) Then
line = line.Trim()
If line.StartsWith("物理地址") Then
macs.Add(line.Substring(line.IndexOf(":") + 1))
End If
End If
line = reader.ReadLine()
End While
'等待程序執行完退出進程
p.WaitForExit()
p.Close()
reader.Close()
strMacValue = macs(0)