如何通过VB获取网卡地址

2016-02-19 21:47 43 1 收藏

有了下面这个如何通过VB获取网卡地址教程,不懂如何通过VB获取网卡地址的也能装懂了,赶紧get起来装逼一下吧!

【 tulaoshi.com - 编程语言 】

1)在Visual Basic生成标准的EXE文件。缺省创建 Form1。
2)在Form1中添加一命令按钮,缺省名为Command1。
3)把下列代码放到Form1中说明部分。

Option Explicit
Private Const NCBASTAT = &H33
Private Const NCBNAMSZ = 16
Private Const HEAP_ZERO_MEMORY = &H8
Private Const HEAP_GENERATE_EXCEPTIONS = &H4
Private Const NCBRESET = &H32

Private Type NCB
ncb_command As Byte 'Integer
ncb_retcode As Byte 'Integer
ncb_lsn As Byte 'Integer
ncb_num As Byte ' Integer
ncb_buffer As Long 'String
ncb_length As Integer
ncb_callname As String * NCBNAMSZ
ncb_name As String * NCBNAMSZ
ncb_rto As Byte 'Integer
ncb_sto As Byte ' Integer
ncb_post As Long
ncb_lana_num As Byte 'Integer
ncb_cmd_cplt As Byte 'Integer
ncb_reserve(9) As Byte ' Reserved, must be 0
ncb_event As Long
End Type

Private Type ADAPTER_STATUS
adapter_address(5) As Byte 'As String * 6
rev_major As Byte 'Integer
reserved0 As Byte 'Integer
adapter_type As Byte 'Integer
rev_minor As Byte 'Integer
duration 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

(本文来源于图老师网站,更多请访问http://www.tulaoshi.com/bianchengyuyan/)

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

(本文来源于图老师网站,更多请访问http://www.tulaoshi.com/bianchengyuyan/)

把下面的代码放入Command1_Click的事件中:

Private Sub Command1_Click()
Dim myNcb As NCB
Dim bRet As Byte
myNcb.ncb_command = NCBRESET
bRet = Netbios(myNcb)
myNcb.ncb_command = NCBASTAT
myNcb.ncb_lana_num = 0
myNcb.ncb_callname = "* "
Dim myASTAT As ASTAT, tempASTAT As ASTAT
Dim pASTAT As Long
myNcb.ncb_length = Len(myASTAT)
Debug.Print Err.LastDllError
pASTAT = HeapAlloc(GetProcessHeap(), HEAP_GENERATE_EXCEPTIONS Or HEAP_ZERO_MEMORY, myNcb.ncb_length)
If pASTAT = 0 Then
Debug.Print "memory allcoation failed!"
Exit Sub
End If
myNcb.ncb_buffer = pASTAT
bRet = Netbios(myNcb)
Debug.Print Err.LastDllError
CopyMemory myASTAT, myNcb.ncb_buffer, Len(myASTAT)
MsgBox Hex(myASTAT.adapt.adapter_address(0)) & " " & Hex(myASTAT.adapt.adapter_address(1)) _
& " " & Hex(myASTAT.adapt.adapter_address(2)) & " " _
& Hex(myASTAT.adapt.adapter_address(3)) _
& " " & Hex(myASTAT.adapt.adapter_address(4)) & " " _
& Hex(myASTAT.adapt.adapter_address(5))
HeapFree GetProcessHeap(), 0, pASTAT
End Su
5)点击Command1。注意,网卡地址将在一信息框中显示出来。

来源:http://www.tulaoshi.com/n/20160219/1627163.html

延伸阅读
[程序语言]MicrosoftVisualBasic4.0,5.0,6.0 [运行平台]WINDOWS [功能描述]IPX和NETBIOS接口需要网络地址。该文通过详细的步骤演示了如何通过VB获取网卡地址。 步骤: 1)在VisualBasic生成标准的EXE文件。缺省创建Form1。 2)在Form1中添加一命令按钮,缺省名为Command1。 3)把下列代码放到Form1中说明部分。 ...
标签: Web开发
代码如下: reg = /[img|href][^]*src\s*=\s*('|")?([^'"]*)\1([^])*/ig 正则获取图片地址 一、问题: 采集的过程中遇到一个问题:从数据库里读出来的图片没有正常显示,分析后发现是数据库里的图片以网站根目录为相对路径方式存储,图片地址如:http://img.warting.com/allimg/090403/012F31N9-1.jpg,原来做的读取图片是以http://...
privatestring[]GetMoc() { string[]str=newstring[3]; ManagementClassmcCpu=newManagementClass("win32_Processor"); ManagementObjectCollectionmocCpu=mcCpu.GetInstances(); foreach(ManagementObjectminmocCpu) { str[0]=m["ProcessorId"].ToString(); } ManagementClassmcHD=newManagementClass("win32_logicaldisk"); Manage...
win7系统下如何查看本地ip地址、网卡物理地址的方法   IP地址是IP协议提供的一种统一的地址格式,它为互联网上的每一个网络和每一台主机分配一个逻辑地址,以此来屏蔽物理地址的差异。网卡的物理地址通常是由网卡生产厂家烧入网卡的EPROM(一种闪存芯片,通常可以通过程序擦写),它存储的是传输数据时真正赖以标识发出数据的电脑和接收...
在Delphi中选Project Import Type Library命令,在对话框中选Import Microsoft Shell Controls And Automation类型库,点Install后,在Delphi的ActiveX控件板上就多了TShellFolderItem,TShellLinkObject,TShellFolderView,TShell,TSearchCommand等几个组件 const    discVerb = '禁用(&B)';  ...

经验教程

145

收藏

58
微博分享 QQ分享 QQ空间 手机页面 收藏网站 回到头部