vb.net取mac源码 vb imports

vb获取网卡mac的完整代码VB获取网卡MAC地址源代码
具体代码vb.net取mac源码:(其中GetMACAddress() 函数为楼主所需函数)
Option Explicit
Public CheckCode As Long
Private Const NCBASTATAs Long = H33
Private Const NCBNAMSZAs Integer = 16
Private Const HEAP_ZERO_MEMORYAs Long = H8
Private Const HEAP_GENERATE_EXCEPTIONSAs Long = H4
Private Const NCBRESETAs Long = H32
Private Type NCB
ncb_commandAs Byte
ncb_retcodeAs Byte
ncb_lsnAs Byte
ncb_numAs Byte
ncb_bufferAs Long
ncb_lengthAs Integer
ncb_callnameAs String * NCBNAMSZ
ncb_nameAs String * NCBNAMSZ
ncb_rtoAs Byte
ncb_stoAs Byte
ncb_postAs Long
ncb_lana_numAs Byte
ncb_cmd_cpltAs Byte
ncb_reserve(9)As Byte
ncb_eventAs Long
End Type
Private Type ADAPTER_STATUS
adapter_address(5)As Byte
rev_majorAs Byte
reserved0As Byte
adapter_typeAs Byte
rev_minorAs Byte
durationAs Integer
frmr_recvAs Integer
frmr_xmitAs Integer
iframe_recv_errAs Integer
xmit_abortsAs Integer
xmit_successAs Long
recv_successAs Long
iframe_xmit_errAs Integer
recv_buff_unavailAs Integer
t1_timeoutsAs Integer
ti_timeoutsAs Integer
Reserved1As Long
free_ncbsAs Integer
max_cfg_ncbsAs Integer
max_ncbsAs Integer
xmit_buf_unavailAs Integer
max_dgram_sizeAs Integer
pending_sessAs Integer
max_cfg_sessAs Integer
max_sessAs Integer
max_sess_pkt_sizeAs Integer
name_countAs Integer
End Type
Private Type NAME_BUFFER
nameAs String * NCBNAMSZ
name_numAs Integer
name_flagsAs Integer
End Type
Private Type ASTAT
adaptAs 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 bRetAs Byte
Dim myNcbAs NCB
Dim myASTAT As ASTAT
Dim pASTATAs 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 = intMACmyASTAT.adapt.adapter_address(1)
intMAC = intMACmyASTAT.adapt.adapter_address(2)
intMAC = intMACmyASTAT.adapt.adapter_address(3)
intMAC = intMACmyASTAT.adapt.adapter_address(4)
intMAC = intMACmyASTAT.adapt.adapter_address(5)
GetMAC = intMAC
Call HeapFree(GetProcessHeap(), 0, pASTAT)
End Function
Public Function GetMACAddress() As String
Dim bRetAs Byte
Dim myNcbAs NCB
Dim myASTAT As ASTAT
Dim pASTATAs 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
【vb.net取mac源码 vb imports】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
VB.NET 获取网关IP MAC地址我找了一些C# 的VB 。NET 貌似很少不过都是 。NET 平台 。你看看吧都应该通用的 。
添加对System.Management的引用
usingSystem.Management;
。。。
//获取IP,子网掩码(subnetmask)和默认网关
ManagementClassmc=newManagementClass( "Win32_NetworkAdapterConfiguration ");
ManagementObjectCollectionnics=mc.GetInstances();
foreach(ManagementObjectnicinnics)
{
if(Convert.ToBoolean(nic[ "ipEnabled "])==true)
{
Console.WriteLine((nic[ "IPAddress "]asString[])[0]);
Console.WriteLine((nic[ "IPSubnet "]asString[])[0]);
Console.WriteLine((nic[ "DefaultIPGateway "]asString[])[0]);
}
}
获取硬件信息源代码:
获取硬件信息演示程序:
汉化
利用usingSystem.Management类来获取相应的硬件知识
其实这类东西很容易找到答案的 , 方法非常多,最常见的API模式,你去搜索吧,保证一把一把的
用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.net取mac源码和vb imports的介绍到此就结束了,不知道你从中找到你需要的信息了吗 ?如果你还想了解更多这方面的信息,记得收藏关注本站 。

    推荐阅读