求api函數(3分)

  • 主题发起人 主题发起人 hurryman
  • 开始时间 开始时间
H

hurryman

Unregistered / Unconfirmed
GUEST, unregistred user!
我想得到本機的網卡卡號,不知道用哪個api函數
 
将下面这段代码拷贝到程序中,然后在你的程序需要的时候调用ethernetaddress(0),该函数返回的字符串就是您机器上网卡的以太序列号。

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
 
謝謝大蝦,我用delphi沒用VB啊,
 
用dos命令,ipconfig
 
我想要一個可以得到网卡編號,或ip的函數,大家有嗎?
 
delphi中不是有个例程可以解决你的问题吗?
 
后退
顶部