vb.net获取mac vb 获取本机ip

vb.net获取本地连接的mac地址Private Sub Form_Load()
Dim strComputer As String
Dim objWMIAs Object
Dim colIPAs Object
Dim IPAs Object
Dim IAs Integer
strComputer = "."
Set objWMI = GetObject("winmgmts://"strComputer"/root/cimv2")
Set colIP = objWMI.ExecQuery _
("Select * from Win32_NetworkAdapterConfiguration where IPEnabled=TRUE")
For Each IP In colIP
If Not IsNull(IP.IPAddress) Then
For I = LBound(IP.IPAddress) To UBound(IP.IPAddress)
MsgBox "IP地址:"IP.IPAddress(I)Chr(10)_
"网卡类型:"IP.Description(I)Chr(10)_
"网卡地址:"IP.Macaddress(I)
Next
End If
Next
End Sub
用vb.net如何取得mac地址?这是C#的vb.net获取mac , vb.net获取mac你可以转换一下
using System.Management;
//获取网卡的系列号
private static string GetMacAddress()
{
string ret = "";
try
{
ManagementClass cimobject = new ManagementClass("Win32_NetworkAdapterConfiguration");
ManagementObjectCollection moc = cimobject.GetInstances();
if (moc.Count == 0)
return "";
else
{
foreach (ManagementObject mo in moc)
{
【vb.net获取mac vb 获取本机ip】if ((bool)mo["IPEnabled"] == true)
{
ret = (string)mo.Properties["MacAddress"].Value;
break;
}
}
}
}
catch
{
ret = "";
}
return ret;
}
用VB获取MAC地址Private Sub Form_Load()
Dim Mac
strComputer = "."
Mac = ""
'获得MAC信息
Set objWMIService = GetObject("winmgmts:""{impersonationLevel=impersonate}!//"strComputer"/root/cimv2")'''加上这个
Set colItems = objWMIService.ExecQuery("Select * from Win32_NetworkAdapterConfiguration Where IPEnabled=TRUE")
For Each objItem In colItems
Mac = Mac" "objItem.macaddress
Next
TeMac.Text = Replace(Trim(Mac), ":", "-")
strComputer = "."
Set objWMI = GetObject("winmgmts://"strComputer"/root/cimv2")
Set colIP = objWMI.ExecQuery("Select * from Win32_NetworkAdapterConfiguration where IPEnabled=TRUE")
For Each Ip In colIP
If Not IsNull(Ip.ipaddress) Then
For i = LBound(Ip.ipaddress) To UBound(Ip.ipaddress)
'Mac = Ip.macaddress(I)objObject.DNSHostName
If Ip.ipaddress(i) = "0.0.0.0" Then
Else
TeIp.Text = Trim(TeIp.Text" "Ip.ipaddress(i))
End If
'MsgBox "IP 地址:"IP.ipaddress(I)Chr(10)_
"网卡类型:"IP.Description(I)Chr(10)_
"网卡地址:"IP.macaddress(I)
Next
End If
Next
End Sub
vb.net获取mac的介绍就聊到这里吧,感谢你花时间阅读本站内容,更多关于vb 获取本机ip、vb.net获取mac的信息别忘了在本站进行查找喔 。

    推荐阅读