您的位置:程序门 -> vb ->



用vb取网卡mac地址为什么取不出来?■■■


[收藏此页] [打印本页]选择字色:背景色:字体:[][][]


用vb取网卡mac地址为什么取不出来?■■■
发表于:2007-02-01 21:55:15 楼主
在csdn上找了取网卡mac地址的vb程序,但在取出来的是0000000。哪位高手能提供一种解决方法。谢谢了!      
发表于:2007-02-02 19:48:051楼 得分:0
小弟到是知道一种笨方法   ipconfig   /all   > 1.txt
延时   分析字符串     不过好象不大稳定哈
发表于:2007-02-02 20:32:302楼 得分:0
private   sub   command1_click()
dim   oadapters   as   object,   oadapter   as   object
on   error   resume   next
set   oadapters   =   getobject( "winmgmts: ").EXECquery( "select   *   from   win32_networkadapterconfiguration   where   ipenabled   =   true ")
for   each   oadapter   in   oadapters
msgbox   "mac   address:     "   &   replace(oadapter.macaddress,   ": ",   "   ")
exit   for
next
end   sub
发表于:2007-02-03 11:20:533楼 得分:0
以上方法都解决不了问题!
发表于:2007-02-03 12:03:304楼 得分:0
你用getmac   > > 1.txt
然后分析1.txt
发表于:2007-02-05 11:23:075楼 得分:0
网卡没有激活,当然取出来是这个样子
发表于:2007-02-05 20:26:566楼 得分:0
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
        dim   myastat   as   astat,   tempastat   as   astat
        dim   pastat   as   long
       
        myncb.ncb_command   =   ncbreset
        bret   =   netbios(myncb)
        myncb.ncb_command   =   ncbastat
        myncb.ncb_lana_num   =   0
        myncb.ncb_callname   =   "*         "
        myncb.ncb_length   =   len(myastat)
       
        pastat   =   heapalloc(getprocessheap(),   heap_generate_exceptions   or   heap_zero_memory,   myncb.ncb_length)
        if   pastat   =   0   then   exit   sub
       
        myncb.ncb_buffer   =   pastat
        bret   =   netbios(myncb)
        copymemory   myastat,   myncb.ncb_buffer,   len(myastat)
       
        debug.print   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
发表于:2007-02-05 20:33:087楼 得分:0
遇到过,也不知道怎么解决,可能是系统版本和权限导致的吧
发表于:2007-02-10 21:35:298楼 得分:0
我曾经遇到过这样的问题,当时的机器是双网卡,一块pci的,一块wifi的,wifi在使用,pci没有插网线,结果取到的就是0,但同样的程序在单网卡的机器或双网卡都通的机器上没有任何问题
发表于:2007-02-10 22:03:039楼 得分:0
bugstudio(bug)   (   )   信誉:100         blog     2007-2-5   20:26:57     得分:   0    
的读出来00000000


private   sub   command1_click()
dim   oadapters   as   object,   oadapter   as   object
on   error   resume   next
set   oadapters   =   getobject( "winmgmts: ").EXECquery( "select   *   from   win32_networkadapterconfiguration   where   ipenabled   =   true ")
for   each   oadapter   in   oadapters
msgbox   "mac   address:     "   &   replace(oadapter.macaddress,   ": ",   "   ")
exit   for
next
end   sub这个可以
发表于:2007-02-10 23:33:2510楼 得分:0
这个做法,可以的,wifi在线+普通卡断线。

sub   main()

dim   oadapters   as   object,   oadapter   as   object
on   error   resume   next
set   oadapters   =   getobject( "winmgmts: ").EXECquery( "select   *   from   win32_networkadapterconfiguration   where   ipenabled   =   true ")
for   each   oadapter   in   oadapters
msgbox   "mac   address:     "   &   replace(oadapter.macaddress,   ": ",   "   ")
exit   for
next

end   sub

   

发表于:2007-04-20 15:22:1111楼 得分:0
cangwu_lee(橙子)   (   )   信誉:98         blog       加为好友     2007-2-10   23:33:26     得分:   0    
 
 
     
这个做法,可以的,wifi在线+普通卡断线。

sub   main()

dim   oadapters   as   object,   oadapter   as   object
on   error   resume   next
set   oadapters   =   getobject( "winmgmts: ").EXECquery( "select   *   from   win32_networkadapterconfiguration   where   ipenabled   =   true ")
for   each   oadapter   in   oadapters
msgbox   "mac   address:     "   &   replace(oadapter.macaddress,   ": ",   "   ")
exit   for
next

end   sub

    ==========================================================
2003下测试通过
发表于:2007-04-21 21:32:2712楼 得分:0
....没发言的份了....

一般的api函数写的代码取的时候都有可能取不回来...

几位大虾写的wmi方式应该没问题....

另外还有个办法,就是写一段汇编存到数组然后调用....
发表于:2007-05-18 22:29:0213楼 得分:0
sub   wmigetmac()
    dim   wmiobjset,   obj
    set   wmiobjset   =   getobject( "winmgmts:{impersonationlevel=impersonate} ").   _
                                                        instancesof( "win32_networkadapterconfiguration ")
    on   local   error   resume   next
    for   each   obj   in   wmiobjset
            msgbox   obj.macaddress
            msgbox   obj.description
            msgbox   obj.dnshostname
            msgbox   obj.dnsdomain
            if   not   isnull(obj.ipaddress)   then
                  for   i   =   0   to   ubound(obj.ipaddress)
                          msgbox   "ip   address: "   &   obj.ipaddress(i)
                  next
            end   if
    next
end   sub


快速检索

最新资讯
热门点击