'=========================================== 'Desc:获取本机IP地址和子网掩码 'Author:yoyoba(stuyou@126.com) 'Date:2007-11-28 'Modify:2007-12-6 '=========================================== OptionExplicit PublicWithEvents vpcap As vbPacket '声明一个使用vbpcap事件的vpcap对象变量 Dim AdapterString AsString* 1000 'GetAdapterNames函数返回的网卡名,存放于该变量 Dim selAdapterName AsString '在List列表中被选中网卡的名字 PrivateSub Command2_Click() vpcap.CloseAdapter End EndSub PrivateSub Form_Load() Set vpcap =New vbPacket '为对象变量vpcap赋值 Dim NumAdapter AsLong 'GetAdapterNames函数返回的网卡数,存放于该变量 Dim AdapterList Dim i AsInteger
NumAdapter = vpcap.GetAdapterNames(AdapterString) '调用GetAdapterNames函数。获得本机网卡名字 If NumAdapter = 0 Then MsgBox "Founded NONE adapter!,please check it!" EndIf
AdapterList = Split(AdapterString, vbNullChar) '把获得得网卡名置于List控件中 For i = 0 To NumAdapter List1.AddItem AdapterList(i) Next i
EndSub PrivateSub Command1_Click()
Dim NetIP AsLong '返回该网卡的IP Dim NetMask AsLong '返回该网卡的掩码