欢迎光临
我们一直在努力

在vb中如何得到网络中某一台电脑(电脑名)的网卡地址?_visualbasic教程

建站超值云服务器,限时71元/月

[程序语言]MicrosoftVisualBasic4.0,5.0,6.0
[运行平台]WINDOWS
[功能描述]IPX和NETBIOS接口需要网络地址。该文通过详细的步骤演示了如何通过VB获取网卡地址。

步骤:

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

OptionExplicit
PrivateConstNCBASTAT=&H33
PrivateConstNCBNAMSZ=16
PrivateConstHEAP_ZERO_MEMORY=&H8
PrivateConstHEAP_GENERATE_EXCEPTIONS=&H4
PrivateConstNCBRESET=&H32

PrivateTypeNCB
  ncb_commandAsByteInteger
  ncb_retcodeAsByteInteger
  ncb_lsnAsByteInteger
  ncb_numAsByteInteger
  ncb_bufferAsLongString
  ncb_lengthAsInteger
  ncb_callnameAsString*NCBNAMSZ
  ncb_nameAsString*NCBNAMSZ
  ncb_rtoAsByteInteger
  ncb_stoAsByteInteger
  ncb_postAsLong
  ncb_lana_numAsByteInteger
  ncb_cmd_cpltAsByteInteger
  ncb_reserve(9)AsByteReserved,mustbe0
  ncb_eventAsLong
EndType

PrivateTypeADAPTER_STATUS
  adapter_address(5)AsByteAsString*6
  rev_majorAsByteInteger
  reserved0AsByteInteger
  adapter_typeAsByteInteger
  rev_minorAsByteInteger
  durationAsInteger
  frmr_recvAsInteger
  frmr_xmitAsInteger
  iframe_recv_errAsInteger
  xmit_abortsAsInteger
  xmit_successAsLong
  recv_successAsLong
  iframe_xmit_errAsInteger
  recv_buff_unavailAsInteger
  t1_timeoutsAsInteger
  ti_timeoutsAsInteger
  Reserved1AsLong
  free_ncbsAsInteger
  max_cfg_ncbsAsInteger
  max_ncbsAsInteger
  xmit_buf_unavailAsInteger
  max_dgram_sizeAsInteger
  pending_sessAsInteger
  max_cfg_sessAsInteger
  max_sessAsInteger
  max_sess_pkt_sizeAsInteger
  name_countAsInteger
EndType

PrivateTypeNAME_BUFFER
  nameAsString*NCBNAMSZ
  name_numAsInteger
  name_flagsAsInteger
EndType

PrivateTypeASTAT
  adaptAsADAPTER_STATUS
  NameBuff(30)AsNAME_BUFFER
EndType

PrivateDeclareFunctionNetbiosLib”netapi32.dll”(pncbAsNCB)AsByte
PrivateDeclareSubCopyMemoryLib”kernel32″Alias”RtlMoveMemory”(hpvDestAsAny,ByValhpvSourceAsLong,ByValcbCopyAsLong)
PrivateDeclareFunctionGetProcessHeapLib”kernel32″()AsLong
PrivateDeclareFunctionHeapAllocLib”kernel32″(ByValhHeapAsLong,ByValdwFlagsAsLong,ByValdwBytesAsLong)AsLong
PrivateDeclareFunctionHeapFreeLib”kernel32″(ByValhHeapAsLong,ByValdwFlagsAsLong,lpMemAsAny)AsLong

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

PrivateSubCommand1_Click()
  DimmyNcbAsNCB
  DimbRetAsByte
  myNcb.ncb_command=NCBRESET
  bRet=Netbios(myNcb)
  myNcb.ncb_command=NCBASTAT
  myNcb.ncb_lana_num=0
  myNcb.ncb_callname=”*      ”
  DimmyASTATAsASTAT,tempASTATAsASTAT
  DimpASTATAsLong
  myNcb.ncb_length=Len(myASTAT)
  Debug.PrintErr.LastDllError
  pASTAT=HeapAlloc(GetProcessHeap(),HEAP_GENERATE_EXCEPTIONSOrHEAP_ZERO_MEMORY,myNcb.ncb_length)
  IfpASTAT=0Then
    Debug.Print”memoryallcoationfailed!”
    ExitSub
  EndIf
  myNcb.ncb_buffer=pASTAT
  bRet=Netbios(myNcb)
  Debug.PrintErr.LastDllError
  CopyMemorymyASTAT,myNcb.ncb_buffer,Len(myASTAT)
  MsgBoxHex(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))
  HeapFreeGetProcessHeap(),0,pASTAT
EndSub

4)按F5,运行该程序。
5)点击Command1。注意,网卡地址将在一信息框中显示出来。->

赞(0)
版权申明:本站文章部分自网络,如有侵权,请联系:west999com@outlook.com 特别注意:本站所有转载文章言论不代表本站观点! 本站所提供的图片等素材,版权归原作者所有,如需使用,请与原作者联系。未经允许不得转载:IDC资讯中心 » 在vb中如何得到网络中某一台电脑(电脑名)的网卡地址?_visualbasic教程
分享到: 更多 (0)