您的位置:程序门 -> vb -> 网络编程



怎么用vb获取网卡的地址


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


怎么用vb获取网卡的地址
发表于:2008-02-27 12:41:29 楼主
我网上找到了种方法,但是在有的机器上显示正确,在有的机器上显示为000000000000

附我找到的代码
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      
            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      
       
    private       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      
       
    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       function       ethernetaddress(lananumber       as       long)       as       string      
            dim       udtncb                               as       ncb      
            dim       bytresponse           as       byte      
            dim       udtastat                       as       astat      
            dim       udttempastat       as       astat      
            dim       lngastat                       as       long      
            dim       strout                               as       string      
            dim       x                                                   as       integer      
            udtncb.ncb_command       =       ncbreset      
            bytresponse       =       netbios(udtncb)      
            udtncb.ncb_command       =       ncbastat      
            udtncb.ncb_lana_num       =       lananumber      
            udtncb.ncb_callname       =       "*       "      
            udtncb.ncb_length       =       len(udtastat)      
            lngastat       =       heapalloc(getprocessheap(),       heap_generate_exceptions       or       heap_zero_memory,       udtncb.ncb_length)      
            strout       =       ""      
            if       lngastat       then      
                    udtncb.ncb_buffer       =       lngastat      
                    bytresponse       =       netbios(udtncb)      
                    copymemory       udtastat,       udtncb.ncb_buffer,       len(udtastat)      
                        with       udtastat.adapt      
                            for       x       =       0       to       5      
                                    strout       =       strout       &       right$("00"       &       hex$(.adapter_address(x)),       2)      
                            next       x      
                    end       with      
                    heapfree       getprocessheap(),       0,       lngastat      
            end       if      
            ethernetaddress       =       strout      
    end       function      
       
       
    private       sub       cmdclose_click()      
            end      
    end       sub      
       
    private       sub       form_load()      
       
            msgbox       ethernetaddress(0)      
       
    end       sub
发表于:2008-02-27 16:31:001楼 得分:0
'试看这个吧   这代码得到的网卡的地址与你的代码结果是一样的

private   sub   form_load()
      msgbox   macaddress
end   sub

private   function   macaddress()   as   string
      set   objs   =   getobject("winmgmts:").EXECquery("select   macaddress   "   &   "from   win32_networkadapter   "   &   "where   "   &   "((macaddress   is   not   null)   "   &   "and   (manufacturer   <>   "   &   "'microsoft'))")
      for   each   obj   in   objs
            macaddress   =   obj.macaddress
            exit   for
      next   obj
end   function


发表于:2008-02-27 16:55:322楼 得分:0
自己查找注册表吧
发表于:2008-02-27 21:55:103楼 得分:0
谢cbm666,
我想要的哦。


快速检索

最新资讯
热门点击