㈠ VB如何获取网卡MAC地址,请给出代码
获取mac地址,其实可以换一个思路,通过获取命令ipconfig /all 的内容,然后通过字符串匹配就可以获得了。
㈡ 用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
㈢ VB6.0 怎么获得本机的IP和mac地址
gethostname 获取本机名字,gethostbyname 通过前面的名字获取主机具体信息,包括IP地址。MAC地址可以用 Netbios,以上用到的函数都是WIN32 API,具体代码请留联系方式(email或者企鹅)也可以自己网络有现成的VB代码
㈣ 用vb.net如何取得mac地址
刚刚我自己写了一段是引用System.net来做的我不喜欢用WMI主要是查出来的信息不准确,下面我附上源码希望可以加分给我
ImportsSystem.Net
ImportsSystem.Net.NetworkInformation
PublicClassForm1
PrivateSubbtnGetMac_Click(ByValsenderAsSystem.Object,ByValeAsSystem.EventArgs)HandlesbtnGetMac.Click
DimNetworkInterfaces()AsNetworkInterface
NetworkInterfaces=NetworkInterface.GetAllNetworkInterfaces()
IfNetworkInterfaces.Length>0Then
txtMac.Text=txtMac.Text+
"MAC地址:"+NetWork.GetPhysicalAddress().ToString()+Environment.NewLine+
"网络连接:"+NetWork.Name+Environment.NewLine+
"网卡序列号:"+NetWork.Id+Environment.NewLine+
"网络类型:"+NetWork.NetworkInterfaceType.ToString()+Environment.NewLine+
"网络速度:"+(NetWork.Speed/1000000).ToString()+"MB"+Environment.NewLine
Next
EndIf
EndSub
EndClass
㈤ 如何用VB编程,获取网关MAC
一、用nbtstat -a ip 命令,用.net中processstartinfo和process类取得命令输出,最后一行就是mac地址 mac address.
二、用.net中的wmi:system.management namespace hosted in system.management.dll assembly
例:
managementobjectsearcher query = new managementobjectsearcher(
㈥ 如何用VB获得机器的MAC地址
PrivateSubForm_Load()
GetMyIP
EndSub
SubGetMyIP()'获取IP地址、网卡类型、网卡地址
DimstrComputerAsString
DimobjWMIAsObject
DimcolIPAsObject
DimIPAsObject
DimIAsInteger
strComputer="."
SetobjWMI=GetObject("winmgmts://"&strComputer&"/root/cimv2")
SetcolIP=objWMI.ExecQuery_
("Select*fromWin32_=TRUE")
ForEachIPIncolIP
IfNotIsNull(IP.IPAddress)Then
ForI=LBound(IP.IPAddress)ToUBound(IP.IPAddress)
MsgBox"IP地址:"&IP.IPAddress(I)&Chr(10)&_
"网卡类型:"&IP.Description(I)&Chr(10)&_
"网卡地址:"&IP.Macaddress(I)
Next
EndIf
Next
EndSub
㈦ 用vb.net如何取得mac地址
这是C#的,你可以转换一下
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)
{
if ((bool)mo["IPEnabled"] == true)
{
ret = (string)mo.Properties["MacAddress"].Value;
break;
}
}
}
}
catch
{
ret = "";
}
return ret;
}
㈧ VB读取MAC地址
楼主可以搜搜
网络文库 源码爱好者 等等网站
'Downlod by http://www.codefans.net
Option Explicit
Public CheckCode As Long
Private Const NCBASTAT As Long = &H33
Private Const NCBNAMSZ As Integer = 16
Private Const HEAP_ZERO_MEMORY As Long = &H8
Private Const HEAP_GENERATE_EXCEPTIONS As Long = &H4
Private Const NCBRESET As Long = &H32
Private Type NCB
ncb_command As Byte
ncb_retcode As Byte
ncb_lsn As Byte
ncb_num As Byte
ncb_buffer As Long
ncb_length As Integer
ncb_callname As String * NCBNAMSZ
ncb_name As String * NCBNAMSZ
ncb_rto As Byte
ncb_sto As Byte
ncb_post As Long
ncb_lana_num As Byte
ncb_cmd_cplt As Byte
ncb_reserve(9) As Byte
ncb_event As Long
End Type
Private Type ADAPTER_STATUS
adapter_address(5) As Byte
rev_major As Byte
reserved0 As Byte
adapter_type As Byte
rev_minor As Byte
ration As Integer
frmr_recv As Integer
frmr_xmit As Integer
iframe_recv_err As Integer
xmit_aborts As Integer
xmit_success As Long
recv_success As Long
iframe_xmit_err As Integer
recv_buff_unavail As Integer
t1_timeouts As Integer
ti_timeouts As Integer
Reserved1 As Long
free_ncbs As Integer
max_cfg_ncbs As Integer
max_ncbs As Integer
xmit_buf_unavail As Integer
max_dgram_size As Integer
pending_sess As Integer
max_cfg_sess As Integer
max_sess As Integer
max_sess_pkt_size As Integer
name_count As Integer
End Type
Private Type NAME_BUFFER
name As String * NCBNAMSZ
name_num As Integer
name_flags As Integer
End Type
Private Type ASTAT
adapt As ADAPTER_STATUS
NameBuff(30) As NAME_BUFFER
End Type
Private Declare Function Netbios Lib "netapi32.dll" (pncb As NCB) As Byte
Private Declare Sub CopyMemory Lib "kernel32" Alias "RtlMoveMemory" (hpvDest As Any, _
ByVal hpvSource As Long, _
ByVal cbCopy As Long)
Private Declare Function GetProcessHeap Lib "kernel32" () As Long
Private Declare Function HeapAlloc Lib "kernel32" (ByVal hHeap As Long, _
ByVal dwFlags As Long, _
ByVal dwBytes As Long) As Long
Private Declare Function HeapFree Lib "kernel32" (ByVal hHeap As Long, _
ByVal dwFlags As Long, _
lpMem As Any) As Long
Public Function GetMAC() As Integer
Dim bRet As Byte
Dim myNcb As NCB
Dim myASTAT As ASTAT
Dim pASTAT As Long
Dim intMAC As Integer
myNcb.ncb_command = NCBRESET
bRet = Netbios(myNcb)
With myNcb
.ncb_command = NCBASTAT
.ncb_lana_num = 0
.ncb_callname = "* "
.ncb_length = Len(myASTAT)
pASTAT = HeapAlloc(GetProcessHeap(), HEAP_GENERATE_EXCEPTIONS Or HEAP_ZERO_MEMORY, .ncb_length)
End With
If pASTAT = 0 Then
Exit Function
End If
myNcb.ncb_buffer = pASTAT
bRet = Netbios(myNcb)
CopyMemory myASTAT, myNcb.ncb_buffer, Len(myASTAT)
intMAC = myASTAT.adapt.adapter_address(0)
intMAC = intMAC + myASTAT.adapt.adapter_address(1)
intMAC = intMAC + myASTAT.adapt.adapter_address(2)
intMAC = intMAC + myASTAT.adapt.adapter_address(3)
intMAC = intMAC + myASTAT.adapt.adapter_address(4)
intMAC = intMAC + myASTAT.adapt.adapter_address(5)
GetMAC = intMAC
Call HeapFree(GetProcessHeap(), 0, pASTAT)
End Function
Public Function GetMACAddress() As String
Dim bRet As Byte
Dim myNcb As NCB
Dim myASTAT As ASTAT
Dim pASTAT As Long
myNcb.ncb_command = NCBRESET
bRet = Netbios(myNcb)
With myNcb
.ncb_command = NCBASTAT
.ncb_lana_num = 0
.ncb_callname = "* "
.ncb_length = Len(myASTAT)
pASTAT = HeapAlloc(GetProcessHeap(), HEAP_GENERATE_EXCEPTIONS Or HEAP_ZERO_MEMORY, .ncb_length)
End With
If pASTAT = 0 Then
Exit Function
End If
myNcb.ncb_buffer = pASTAT
bRet = Netbios(myNcb)
CopyMemory myASTAT, myNcb.ncb_buffer, Len(myASTAT)
GetMACAddress = HexEx(myASTAT.adapt.adapter_address(0)) & "-" & HexEx(myASTAT.adapt.adapter_address(1)) & "-" & HexEx(myASTAT.adapt.adapter_address(2)) & "-" & HexEx(myASTAT.adapt.adapter_address(3)) & "-" & HexEx(myASTAT.adapt.adapter_address(4)) & "-" & HexEx(myASTAT.adapt.adapter_address(5))
Call HeapFree(GetProcessHeap(), 0, pASTAT)
End Function
Private Function HexEx(ByVal B As Long) As String
Dim aa As String
aa = Hex$(B)
If Len(aa) < 2 Then
aa = "0" & aa
End If
HexEx = aa
End Function