vb.net 获取本机网卡的物理址

linste 2009-12-14 09:24:53
rt
...全文
252 7 打赏 收藏 转发到动态 举报
写回复
用AI写文章
7 条回复
切换为时间正序
请发表友善的回复…
发表回复
linste 2009-12-14
  • 打赏
  • 举报
回复
[Quote=引用 6 楼 qshurufa 的回复:]
My Project --> 引用 --> 添加 --> 然后在.Net里边找
[/Quote]

原来还需要引用,谢谢
qshurufa 2009-12-14
  • 打赏
  • 举报
回复
My Project --> 引用 --> 添加 --> 然后在.Net里边找
qshurufa 2009-12-14
  • 打赏
  • 举报
回复
引用System.Management
Dim Wmi As New System.Management.ManagementObjectSearcher("SELECT * FROM Win32_NetworkAdapterConfiguration")
For Each WmiObj As Management.ManagementObject In Wmi.Get
If CBool(WmiObj("IPEnabled")) Then
TextBox1.Text = "MAC(" & WmiObj("MACAddress") & ")" End If
Next
mania001 2009-12-14
  • 打赏
  • 举报
回复
没试过,学习一下。
linste 2009-12-14
  • 打赏
  • 举报
回复
谁有vb。net的原码?
linste 2009-12-14
  • 打赏
  • 举报
回复
     
Dim mc As New System.Management.ManagementClass("Win32_NetworkAdapterConfiguration")
Dim moc As System.Management.ManagementObjectCollection = mc.GetInstances()
For Each mo As System.Management.ManagementObject In moc

If CBool(mo("IPEnabled")) = True Then
MessageBox.Show("网卡=" & mo("MacAddress").ToString())
End If
Next

提示:未定义类型System.Management.ManagementClass
宝_爸 2009-12-14
  • 打赏
  • 举报
回复
C#的代码,vb.net应该也差不多。


//Namespace reference
using System.Management;

/// <summary>
/// Returns MAC Address from first Network Card in Computer
/// </summary>
/// <returns>MAC Address in string format</returns>
public string FindMACAddress()
{
//create out management class object using the
//Win32_NetworkAdapterConfiguration class to get the attributes
//af the network adapter
ManagementClass mgmt = new ManagementClass("Win32_NetworkAdapterConfiguration");
//create our ManagementObjectCollection to get the attributes with
ManagementObjectCollection objCol = mgmt.GetInstances();
string address = String.Empty;
//loop through all the objects we find
foreach (ManagementObject obj in objCol)
{
if (address == String.Empty) // only return MAC Address from first card
{
//grab the value from the first network adapter we find
//you can change the string to an array and get all
//network adapters found as well
if ((bool)obj["IPEnabled"] == true) address = obj["MacAddress"].ToString();
}
//dispose of our object
obj.Dispose();
}
//replace the ":" with an empty space, this could also
//be removed if you wish
address = address.Replace(":", "");
//return the mac address
return address;
}

16,555

社区成员

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

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