为了正常的体验网站,请在浏览器设置里面开启Javascript功能!
首页 > VB.NET获取MAC地址

VB.NET获取MAC地址

2018-03-09 5页 doc 17KB 49阅读

用户头像

is_281650

暂无简介

举报
VB.NET获取MAC地址VB.NET获取MAC地址 方法一:nbtstat 命令 Public Function GetMac(ByVal IP As String) As String Try '定义输出变量。 Dim StrMac As String = String.Empty Dim Str As String = String.Empty '定义进程参数。 Dim Info As New ProcessStartInfo Info.FileName = ";nbtstat"; Info.Arguments = ";-a ...
VB.NET获取MAC地址
VB.NET获取MAC地址 一:nbtstat 命令 Public Function GetMac(ByVal IP As String) As String Try '定义输出变量。 Dim StrMac As String = String.Empty Dim Str As String = String.Empty '定义进程参数。 Dim Info As New ProcessStartInfo Info.FileName = ";nbtstat"; Info.Arguments = ";-a "; + IP Info.UseShellExecute = False Info.RedirectStandardInput = False Info.RedirectStandardOutput = True Info.RedirectStandardError = True Info.CreateNoWindow = True Info.WindowStyle = ProcessWindowStyle.Hidden '定义新进程。 Dim mProcess As New Process '开始执行操作。 mProcess = Process.Start(Info) '无限循环按行读取输出内容。 While True '读取一行数据。 Str = mProcess.StandardOutput.ReadLine() mProcess.WaitForExit() StrMac = Str.Trim() '判断是否有 Mac Address字眼。 If StrMac.ToLower.Contains(";mac address";) Then Exit While Else If StrMac.ToLower.Contains(";host not found";) Then Exit While End If End If End While '返回值。 Return StrMac Catch ex As Exception '返回错误值。 Return String.Format(";Get Error. 原因:{0}";, ex.Message) End Try 方法2:SendARP 函数 Private Declare Ansi Function SendARP Lib ";Iphlpapi.dll"; (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_32.dll"; (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 = String.Empty Dim StrMac As String = String.Empty Try Dim MacInfo As New Int64 Dim Len As Int32 = 6 Dim Res As Integer = SendARP(Dest, 0, MacInfo, Len) Str = Convert.ToString(MacInfo, 16).ToUpper If Str.Length = 12 Then '因为取出来的值是反的,所以要处理下。 Dim M(5) As String M(0) = Str.Substring(10, 2) M(1) = Str.Substring(8, 2) M(2) = Str.Substring(6, 2) M(3) = Str.Substring(4, 2) M(4) = Str.Substring(2, 2) M(5) = Str.Substring(0, 2) StrMac = String.Format(";{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 String.Format(";Get Error. 原因:{0}";, ex.Message) End Try Return StrMac End Function 方法3:用WMI,先-引用 Microsoft WMI Scripting V1.1 Library Private Sub wmiSoundDeviceInfo() Dim wmiObjSet As WbemScripting.SWbemObjectSet Dim obj As SWbemObject wmiObjSet = GetObject(";winmgmts:{impersonationLevel=impersonate}";). _ InstancesOf(";Win32_NetworkAdapterConfiguration";) For Each obj In wmiObjSet Debug.Print(obj.MACAddress) Next End Sub 方法4: Imports System.Net.NetworkInformation Function getMacAddress() Dim nics() As NetworkInterface = _ NetworkInterface.GetAllNetworkInterfaces Return nics(0).GetPhysicalAddress.ToString End Function
/
本文档为【VB.NET获取MAC地址】,请使用软件OFFICE或WPS软件打开。作品中的文字与图均可以修改和编辑, 图片更改请在作品中右键图片并更换,文字修改请直接点击文字进行修改,也可以新增和删除文档中的内容。
[版权声明] 本站所有资料为用户分享产生,若发现您的权利被侵害,请联系客服邮件isharekefu@iask.cn,我们尽快处理。 本作品所展示的图片、画像、字体、音乐的版权可能需版权方额外授权,请谨慎使用。 网站提供的党政主题相关内容(国旗、国徽、党徽..)目的在于配合国家政策宣传,仅限个人学习分享使用,禁止用于任何广告和商用目的。

历史搜索

    清空历史搜索