VB编写获取客户端网卡MAC地址的问题

kafly 2006-08-23 04:12:23
控件界面定义了一个标签Lable1,一个按钮Command1
可结果取出来都是0。。。

另外,生成的OCX在HTM里调用也有问题。。老是红叉叉,CLASSID没有错。IE浏览器权限也都给了。


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

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

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)
Label1.Caption = 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 Sub
...全文
272 4 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
kafly 2006-08-25
  • 打赏
  • 举报
回复
还是自己的代码管用,不过2003下取不来
kafly 2006-08-23
  • 打赏
  • 举报
回复
我在非技术类里有个100分的帖,希望高手能帮忙
happy_sea 2006-08-23
  • 打赏
  • 举报
回复
MsgBox GetMACAddress()
以上代码在Windows XP sp1系统环境中测试成功
happy_sea 2006-08-23
  • 打赏
  • 举报
回复
Option Explicit


Public Const NCBASTAT As Long = &H33
Public Const NCBNAMSZ As Long = 16
Public Const HEAP_ZERO_MEMORY As Long = &H8
Public Const HEAP_GENERATE_EXCEPTIONS As Long = &H4
Public Const NCBRESET As Long = &H32

Public Type NET_CONTROL_BLOCK '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 ' Reserved, must be 0
ncb_event As Long
End Type

Public Type ADAPTER_STATUS
adapter_address(5) As Byte
rev_major As Byte
reserved0 As Byte
adapter_type As Byte
rev_minor As Byte
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


Public Type NAME_BUFFER
name As String * NCBNAMSZ
name_num As Integer
name_flags As Integer
End Type

Public Type ASTAT
adapt As ADAPTER_STATUS
NameBuff(30) As NAME_BUFFER
End Type

Public Declare Function Netbios Lib "netapi32.dll" (pncb As NET_CONTROL_BLOCK) As Byte

Public Declare Sub CopyMemory Lib "kernel32" Alias "RtlMoveMemory" (hpvDest As Any, ByVal hpvSource As Long, ByVal cbCopy As Long)

Public Declare Function GetProcessHeap Lib "kernel32" () As Long


Public Declare Function HeapAlloc Lib "kernel32" (ByVal hHeap As Long, ByVal dwFlags As Long, ByVal dwBytes As Long) As Long

Public Declare Function HeapFree Lib "kernel32" (ByVal hHeap As Long, ByVal dwFlags As Long, lpMem As Any) As Long


Public Function GetMACAddress() As String

'retrieve the MAC Address for the network controller
'installed, returning a formatted string

Dim tmp As String
Dim pASTAT As Long
Dim NCB As NET_CONTROL_BLOCK
Dim AST As ASTAT

'The IBM NetBIOS 3.0 specifications defines four basic
'NetBIOS environments under the NCBRESET command. Win32
'follows the OS/2 Dynamic Link Routine (DLR) environment.
'This means that the first NCB issued by an application
'must be a NCBRESET, with the exception of NCBENUM.
'The Windows NT implementation differs from the IBM
'NetBIOS 3.0 specifications in the NCB_CALLNAME field.
NCB.ncb_command = NCBRESET
Call Netbios(NCB)

'To get the Media Access Control (MAC) address for an
'ethernet adapter programmatically, use the Netbios()
'NCBASTAT command and provide a "*" as the name in the
'NCB.ncb_CallName field (in a 16-chr string).
NCB.ncb_callname = "* "
NCB.ncb_command = NCBASTAT

'For machines with multiple network adapters you need to
'enumerate the LANA numbers and perform the NCBASTAT
'command on each. Even when you have a single network
'adapter, it is a good idea to enumerate valid LANA numbers
'first and perform the NCBASTAT on one of the valid LANA
'numbers. It is considered bad programming to hardcode the
'LANA number to 0 (see the comments section below).
NCB.ncb_lana_num = 0
NCB.ncb_length = Len(AST)

pASTAT = HeapAlloc(GetProcessHeap(), HEAP_GENERATE_EXCEPTIONS _
Or HEAP_ZERO_MEMORY, NCB.ncb_length)

If pASTAT = 0 Then
Debug.Print "memory allocation failed!"
Exit Function
End If

NCB.ncb_buffer = pASTAT
Call Netbios(NCB)

CopyMemory AST, NCB.ncb_buffer, Len(AST)

tmp = Format$(Hex(AST.adapt.adapter_address(0)), "00") & " " & _
Format$(Hex(AST.adapt.adapter_address(1)), "00") & " " & _
Format$(Hex(AST.adapt.adapter_address(2)), "00") & " " & _
Format$(Hex(AST.adapt.adapter_address(3)), "00") & " " & _
Format$(Hex(AST.adapt.adapter_address(4)), "00") & " " & _
Format$(Hex(AST.adapt.adapter_address(5)), "00")


HeapFree GetProcessHeap(), 0, pASTAT

GetMACAddress = tmp

End Function


◆ 01.htm 1、怎么用mscomm控件检测modem是否与计算机联接正确?2、如何用mscomm挂断modem与别的电话机间的连接?(已接通) ◆ 02.htm CWinInetConnection---一个封装了WinInet API函数的类 ◆ 03.htm MODEM通讯意外处理 ◆ 04.htm MsComm 文字传输 ◆ 05.htm PING一个IP地址(向它发送一个数据包并等待回应) ◆ 06.htm SMTP协议简介 (Simple Mail Transfer Protocol) ◆ 07.htm VB5.0 中远程数据库的访问 ◆ 08.htm VB下如何编写CRC校验程序 ◆ 09.htm VB中Winsock控制的UDP协议的使用 ◆ 10.htm Visual Basic 6中发送邮件的新方法 ◆ 11.htm Visual Basic通信程序设计 ◆ 12.htm Whois 示例程序 ◆ 13.htm Winsock Terminal示例程序 ◆ 14.htm WinSock断开导致客户端问题 ◆ 15.htm 把Outlook信箱中的附件另存为 ◆ 16.htm 保证连网计算机时间同步 ◆ 17.htm 编写网络寻呼机 ◆ 18.htm 编制自已的电话录音小程序 ◆ 19.htm 程序中如何启动默认的拨号连接 ◆ 20.htm 程序中如何启动默认的拨号连接? ◆ 21.htm 打开器并进入指定网址 ◆ 22.htm 打开一个直接到自己主页的器 ◆ 23.htm 得到用户的IP地址 ◆ 24.htm 电话拨号 ◆ 25.htm 电子邮件的标准格式 (RFC 822) ◆ 26.htm 断开拨号网络的连接 ◆ 27.htm 断开与 Internet 的连接 ◆ 28.htm 发送电子邮件附件 ◆ 29.htm 发送电子邮件附件1 ◆ 30.htm 发送电子邮件附件2 ◆ 31.htm 发送电子邮件附件3 ◆ 32.htm 发送电子邮件附件4 ◆ 33.htm 获得用户网络登录名 ◆ 34.htm 基 于Win95 的VB5 串 口 通 信 程 序 ◆ 35.htm 基于Win95的VB5串口通信程序 ◆ 36.htm 几个设置IE的API ◆ 37.htm 检测运程数据传送的断线 ◆ 38.htm 简单的聊天程序 ◆ 39.htm 简单电子邮件发送程序 ◆ 40.htm 建立拨号联接 ◆ 41.htm 将所有窗口最小化 ◆ 42.htm 利用IE控件访问Internet ◆ 43.htm 利用IE控件设计简易器 ◆ 44.htm 利用Mscomm32控件判断MODEM是否打开,或者正在工作,并且判断拨号时是否遇忙音 ◆ 45.htm 利用TAPI进行电话拨号 ◆ 46.htm 利用VB访问Internet ◆ 47.htm 利用VB设计聊天室 ◆ 48.htm 利用Visual Basic实现无线通讯 ◆ 49.htm 利用Winsock控件实现局域网通信 ◆ 50.htm 强制一个本地或远程NT系统关闭 ◆ 51.htm 取得网卡序列号 ◆ 52.htm 如何从 Internet 上取回某一个网页的內容? ◆ 53.htm 如何检测是否已连接到Internet? ◆ 54.htm 如何利用Winsock控件编写自己的Internet程序 ◆ 55.htm 如何每天抓取 Internet 上某一个网页中的图片来更换桌面的壁纸? ◆ 56.htm 如何启动拨号网路中的连线? ◆ 57.htm 如何使用MSCOMM32.OCX发送大于80H的字符,可否给个示例程序 ◆ 58.htm 如何通过VB获取网卡地址 ◆ 59.htm 如何用VB打开默认器或默认发信程序? ◆ 60.htm 如何用Visual Basic编写小型的网络系统 ◆ 61.htm 如何在程序中启动 NT 的【拨号连接】对话框 ◆ 62.htm 如何在程序中启动 NT 的【拨号连接】对话框? ◆ 63.htm 如何在网页上使用 VB5 制作的 ActiveX 控件? ◆ 64.htm 如何中断【拨号网络连接】 ◆ 65.htm 设计Browser及FTP程序 ◆ 66.htm 设计Chat程序 ◆ 67.htm 设计E-mail程序 ◆ 68.htm 设置计算机名称 ◆ 69.htm 使用VB获得一页的HTML代码 ◆ 70.htm 使用VB收发电子邮件 ◆ 71.htm 使用标签控件调出器 ◆ 72.htm 使用超链接和发送Email ◆ 73.htm 使用器的文件复制对话框 ◆ 74.htm 输入/输出篇 ◆ 75.htm 通过WnetEnumResource函数获得网络资源 ◆ 76.htm 通往 Internet 的捷径 ◆ 77.htm 显示计算机的名称 ◆ 78.htm 用 MAPI 控件实现发送邮件 ◆ 79.htm 用 WinSock 控件下载文件 ◆ 80.htm 用 Winsock 实现聊天的程序 ◆ 81.htm 用Internet Transfer编写FTP程序 ◆ 82.htm 用Sockets发送电子邮件 ◆ 83.htm 用VB 创 建 自 己 的 通 信 程 序 ◆ 84.htm 用VB5.0开发通信软件的技巧 ◆ 85.htm 用VB5开发IE ◆ 86.htm 用VB编写网络寻呼 ◆ 87.htm 用VB编写小型的网络系统 ◆ 88.htm 用VB创建自己的通信程序 ◆ 89.htm 用VB构建Internet的应用[微软提供] ◆ 90.htm 用VB开发标准CGI程序 ◆ 91.htm 用VB实现客户——服务器(TCP IP)编程实例 ◆ 92.htm 用VB实现客户服务器(TCP、IP)编程实例 ◆ 93.htm 用VB实现聊天讨论室和点对点会话 ◆ 94.htm 用VB写一个定时PING某IP的程序 ◆ 95.htm 用VB制作器 ◆ 96.htm 用Visual Basic 5.0设计E-mail程序(MAPI) ◆ 97.htm 用Visual Basic6.0编写客户服务器程序 ◆ 98.htm 用Visual Basic创建FTP组件 ◆ 99.htm 用Visual Basic开发数据库器 ◆ 100.htm 用Visual Basic轻松地设计Browser及Ftp程序 ◆ 101.htm 用Winsock控件发信Email ◆ 102.htm 用Winsock控件实现文件的下载 ◆ 103.htm 用Winsock实现点对点通信 ◆ 104.htm 邮件检查程序(二) ◆ 105.htm 邮件检查程序(一) ◆ 106.htm 在VB程序中怎样挂断拨号网络 ◆ 107.htm 在VB中操纵OLE服务器应用程序 ◆ 108.htm 在VB中利用UDP协议编写聊天程序 ◆ 109.htm 在VB中模拟实现邮件传输 ◆ 110.htm 在VB中如何得到网络中某一台电脑(电脑名)的网卡地质? (自己的) ◆ 111.htm 在VB中实现文件上传 ◆ 112.htm 在VB中实现文件上载 ◆ 113.htm 在VB中使用UDP协议 ◆ 114.htm 在VB中用Outlook发电子邮件 ◆ 115.htm 在WindowsNT网络中广播消息 ◆ 116.htm 在程序中打开 Internet 拨号连接窗口 ◆ 117.htm 在一个单位内部或通过广域协议(如X.25)互联的行业内部都有几十或上万台计算机互联,用Intranet虽然可以建立聊天室,但实现点对点实时对话却比较困难。本人用Winsock和VB自制了一套聊天室和对话系统,特拿来供同行们参考。 ◆ 118.htm 在应用中集成器 ◆ 119.htm 在桌面上建立一个 Internet 快捷键 ◆ 120.htm 怎样接收电子邮件(POP3协议简介) ◆ 121.htm 怎样用VB得知系统当前是否处于internet链结状态 ◆ 122.htm 制作自己的网络搜索软件 ◆ 123.htm 自动更新工作站的应用程序 ◆ 124.htm 自己的IE——用VB制作器 ◆ 125.htm HTTP协议(学习笔记) ◆ 126.htm HTTP协议四--关于Chunked编码 ◆ 127.htm IE器完全控制 ◆ 128.htm OICQ服务器系统通讯协议 ◆ 129.htm POP3协议的基本命令 ◆ 130.htm RAS API上的其他Function ◆ 131.htm VB + API 获取 IE 的 “代理服务器” 配制 ◆ 132.htm vb调用winInet API接口post数据到指定的url ◆ 133.htm vb开发通信软件 ◆ 134.htm vb设计数据库电子邮件程序(1) ◆ 135.htm vb设计数据库电子邮件程序(2) ◆ 136.htm vb设计数据库电子邮件程序(3) ◆ 137.htm vb设计数据库电子邮件程序(4) ◆ 138.htm vb设计数据库电子邮件程序(5) ◆ 139.htm vb设计数据库电子邮件程序(6) ◆ 140.htm VB实现应用程序在局域网上自动更新 ◆ 141.htm VB邮件检查程序 ◆ 142.htm vb中从域名得到IP及从IP得到域名 ◆ 143.htm VB中检测是否连网 ◆ 144.htm WebClass实现动态WEB编程之理论篇 ◆ 145.htm Winsocket网络编程谈 ◆ 146.htm Winsock编程框架 ◆ 147.htm Winsock错误代码一览表 ◆ 148.htm 程式自动呼叫拨号网络(RAS API) ◆ 149.htm 打开一个超连接 ◆ 150.htm 得到登入windows 的人的id ◆ 151.htm 访问Internet并调用Explorer ◆ 152.htm 非同步文件下载类 ◆ 153.htm 给Outlook的所有用户发送信件 ◆ 154.htm 获得网卡MAC地址 ◆ 155.htm 基于WinSock的小型网络管理系统及其实现 ◆ 156.htm 检测是否连接到Internet ◆ 157.htm 检测网络是否连通 ◆ 158.htm 建立Web的超链接树形图 ◆ 159.htm 建立你自己的器-Properties ◆ 160.htm 建立你自己的器-查看源文件 ◆ 161.htm 建立你自己的器-打印 ◆ 162.htm 建立你自己的器-打印设置 ◆ 163.htm 建立你自己的器-发送到FontPage ◆ 164.htm 建立你自己的器-发送到Visual Interdev ◆ 165.htm 建立你自己的器-发送到软盘 ◆ 166.htm 建立你自己的器-复制 ◆ 167.htm 建立你自己的器-另存为 ◆ 168.htm 建立你自己的器-全选 ◆ 169.htm 建立你自己的器-页面设置 ◆ 170.htm 开发通信软件的技术与技巧 ◆ 171.htm 开发网络应用的5个技巧 ◆ 172.htm 利用RAS调用在VB6.0中实现拨号上网 ◆ 173.htm 利用VB提取HTML文件中的EMAIL地址 ◆ 174.htm 枚举出局域网上所有网络资源 ◆ 175.htm 面向Internet的开发工具 ◆ 176.htm 你也可以YAI--VB5中Winsock控件的使用 ◆ 177.htm 判断一个文件是否在IE的缓存中 ◆ 178.htm 启动拨号网络中的连接 ◆ 179.htm 浅谈HTTP协议(二)--返回值 ◆ 180.htm 浅谈HTTP协议(一)--结构 ◆ 181.htm 如何利用 WebBrowser 控件显示 .GIF 动画? ◆ 182.htm 如何映射(中断网络磁盘) ◆ 183.htm 设计E-mail的接收部分 ◆ 184.htm 设置器默认网址 ◆ 185.htm 实现端口对端口的聊天 ◆ 186.htm 使用ASP建立Http组件 ◆ 187.htm 使用VB编写纯ASP程序 ◆ 188.htm 使用vb获取网上邻居里的计算机名 ◆ 189.htm 使用VB建立Web Server ◆ 190.htm 使用Visual Basic开发通讯软件 ◆ 191.htm 使用资源工具包执行本地和远程重新启动 ◆ 192.htm 谈谈远程控制中关于搜索、控制计算机的功能 ◆ 193.htm 压缩 Html ◆ 194.htm 用ASP、VB和XML建立互联网应用程序(1) ◆ 195.htm 用ASP、VB和XML建立互联网应用程序(2) ◆ 196.htm 用ASP、VB和XML建立互联网应用程序(3) ◆ 197.htm 用ASP、VB和XML建立互联网应用程序(4) ◆ 198.htm 用COMMUNICATION控件进行数据采集(学习笔记) ◆ 199.htm 用OLE自动化Outlook ◆ 200.htm ActiveX控件用于DHTML开发 ◆ 201.htm 用VB编写ActiveX DLL实现ASP编程 ◆ 202.htm 用VB编写Windows CGI应用程序 ◆ 203.htm 用VB编写标准CGI程序(上) ◆ 204.htm 用VB编写标准CGI程序(下) ◆ 205.htm 用VB编写收发电子邮件程序 ◆ 206.htm 用VB编写网络监控软件 ◆ 207.htm 用VB编写异步多线程下载程序 ◆ 208.htm 用VB导入导出IE器收藏夹 ◆ 209.htm 用VB定制合路器 ◆ 210.htm 用VB和XML建立集中式应用程序 ◆ 211.htm 用VB将Html转换为文本文件 ◆ 212.htm 用VB开发分布式应用 ◆ 213.htm 用VB设计基于代理服务器的网络计费系统 ◆ 214.htm 用VB制作文件下载程序 ◆ 215.htm 用Visual Basic 实现无线通讯 ◆ 216.htm 用Winsock制作一套聊天室和对话系统 ◆ 217.htm 远程共享显示及声音的实现 ◆ 218.htm 远程启动机器ABC API解决方案 ◆ 219.htm 远程启动机器ABC WMI解决方案 ◆ 220.htm 在VB5中利用Winsock和msDNS控件进行 ◆ 221.htm 找出计算机上当前登录入网的用户 ◆ 222.htm 用VB5 Winsock控件创建TCP(IP)客户机 服务器程序

1,453

社区成员

发帖
与我相关
我的任务
社区描述
VB 控件
社区管理员
  • 控件
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

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