[请教]vb.net中如何获得本机mac地址

qqwanjun 2009-07-28 10:46:32
vb.net中如何获得本机mac地址

找了一下,发现有C++的,或者其它代码的,

请那位大虾给段代码,谢谢.
...全文
685 12 打赏 收藏 转发到动态 举报
写回复
用AI写文章
12 条回复
切换为时间正序
请发表友善的回复…
发表回复
wangjuenhui520 2009-08-25
  • 打赏
  • 举报
回复
从楼上各位的代码来看使用了system.menagement命名空间中的类,其实是引用了WMI,也可以使用vbs 的方式引用WMI ,不过写法都差不多,关于9楼所说的多认到一块,那很有可能是多次安装的结果。
Forrest23 2009-08-25
  • 打赏
  • 举报
回复

Dim netAddress As String = ""
Dim netName As String = ""
Dim searcher As New Management.ManagementObjectSearcher("select * from win32_NetworkAdapterConfiguration")
Dim moc2 As Management.ManagementObjectCollection = searcher.Get()
For Each mo As Management.ManagementObject In moc2
If CBool(mo("IPEnabled")) Then '判断是否是网卡
netName = mo.Properties("caption").Value.ToString '网卡名称
netAddress = mo.Properties("MACAddress").Value.ToString 'mac地址
End If
Next
想飞的狼 2009-08-25
  • 打赏
  • 举报
回复
bd
billow_chentao 2009-08-25
  • 打赏
  • 举报
回复
我有三个网卡 Intel 10/100M、D-Link无线、VPeN(VPN软件加上去的)
怎么会取得四个地址,但其中有一个是重复的?如何知道每个地址的网卡名称?
00:0A:E4:2A:8C:B8
08:00:58:00:00:03
00:05:5D:D7:37:6F
00:0A:E4:2A:8C:B8
ldd10345 2009-08-24
  • 打赏
  • 举报
回复
Dim wmi1 As New System.management.ManagementObjectSearcher("select * from win32_processor")
Dim uint321 As String
'Dim uint322 As UInt32
'Dim uint323 As UInt64
Dim uint324 As String
For Each wmiobj As ManagementObject In wmi1.Get
uint321 = wmiobj("processorid")
Next

'获得硬盘序列号
'Dim cmicwmi As New System.management.ManagementObjectSearcher("select * from win32_diskdrive")
'For Each cmicwmiobj As ManagementObject In cmicwmi.Get
' uint322 = cmicwmiobj("signature")
'Next

'获得硬盘总容量
'Dim wmi As New System.management.ManagementObjectSearcher("select * from win32_diskdrive")
'For Each wmiobj As ManagementObject In wmi.Get
' uint323 = wmiobj("size")
'Next

'网卡MAC
Dim Wmi4 As New System.Management.ManagementObjectSearcher("SELECT * FROM Win32_NetworkAdapterConfiguration")
For Each WmiObj As ManagementObject In Wmi4.Get
If CBool(WmiObj("IPEnabled")) Then
uint324 = WmiObj("MACAddress") & vbCrLf
End If
Next
woshisunyi 2009-08-24
  • 打赏
  • 举报
回复
netid = mo.Properties["MACAddress"].Value.ToString
我在VS2003中怎么一直提示无法转换为String?
zyjljlj 2009-07-31
  • 打赏
  • 举报
回复
顶,我也一直在找这个代码.
xue1234567890 2009-07-30
  • 打赏
  • 举报
回复
支持..
shadowjl 2009-07-30
  • 打赏
  • 举报
回复

Dim netid as String=""
Dim searcher as New ManagermentObjectSearch("select * from win32_NetworkAdapterConfiguration")
Dim moc2 as ManagementObjectCollection = searcher.Get()
For Each mo as ManagementObject in moc2
netid = mo.Properties["MACAddress"].Value.ToString
Next

2楼的
kerryhuang 2009-07-30
  • 打赏
  • 举报
回复
现在有些用户使用的是电信的无线网卡,上面的代码好像就读不出MAC地址。。。
Msconfig_001 2009-07-29
  • 打赏
  • 举报
回复
上面是C#的.你转下成VB.NET的就行了.
Msconfig_001 2009-07-29
  • 打赏
  • 举报
回复
//网卡
String netid = "";
ManagementObjectSearcher searcher = new ManagementObjectSearcher("SELECT * FROM Win32_NetworkAdapterConfiguration");
ManagementObjectCollection moc2 = searcher.Get();
foreach (ManagementObject mo in moc2)
{
netid = (string)mo.Properties["MACAddress"].Value;
}

16,554

社区成员

发帖
与我相关
我的任务
社区描述
VB技术相关讨论,主要为经典vb,即VB6.0
社区管理员
  • VB.NET
  • 水哥阿乐
  • 无·法
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧