加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 大数据 > 正文

VB6获取网卡信息

发布时间:2020-12-16 23:03:19 所属栏目:大数据 来源:网络整理
导读:需要用VB6读取网卡网管信息,进行设置,所以找了一段代码,使用的是WMI的系统查询方式,循环所有网络适配器,取得信息 当然可以加判断处理下了。 Option Explicit Dim objSWbemServices As SWbemServices Dim objSWbemObjectSet As SWbemObjectSet Dim objSW

需要用VB6读取网卡网管信息,进行设置,所以找了一段代码,使用的是WMI的系统查询方式,循环所有网络适配器,取得信息

当然可以加判断处理下了。

Option Explicit Dim objSWbemServices As SWbemServices Dim objSWbemObjectSet As SWbemObjectSet Dim objSWbemObject As SWbemObject Private Type NetCard Name As String IPAdress As String IpSubNets As String IpGateWay As String DnsString0 As String DnsString1 As String MacAdress As String End Type Dim MtNetCard() As NetCard Private Sub Command1_Click() Dim i As Long For i = LBound(MtNetCard) To UBound(MtNetCard) - 1 Text1 = Text1 & "网卡: " & MtNetCard(i).Name & vbNewLine Text1 = Text1 & "ip地址: " & MtNetCard(i).IPAdress & vbNewLine Text1 = Text1 & "子网掩码:" & MtNetCard(i).IpSubNets & vbNewLine Text1 = Text1 & "网关: " & MtNetCard(i).IpGateWay & vbNewLine Text1 = Text1 & "DNS1: " & MtNetCard(i).DnsString0 & vbNewLine Text1 = Text1 & "DNS2: " & MtNetCard(i).DnsString1 & vbNewLine Text1 = Text1 & "MAC: " & MtNetCard(i).MacAdress & vbNewLine Next Erase MtNetCard End Sub Private Sub Form_Load() ReDim MtNetCard(0) As NetCard Set objSWbemServices = GetObject("winmgmts:") Set objSWbemObjectSet = objSWbemServices.ExecQuery("Select * From Win32_NetworkAdapterConfiguration Where IPEnabled=TRUE") For Each objSWbemObject In objSWbemObjectSet On Error Resume Next MtNetCard(UBound(MtNetCard)).Name = objSWbemObject.Description '添加本机上已经安装了TCP/IP协议的网卡 MtNetCard(UBound(MtNetCard)).IPAdress = objSWbemObject.IPAddress(0) MtNetCard(UBound(MtNetCard)).IpSubNets = objSWbemObject.IPSubnet(0) MtNetCard(UBound(MtNetCard)).IpGateWay = objSWbemObject.DefaultIPGateway(0) MtNetCard(UBound(MtNetCard)).DnsString0 = objSWbemObject.DNSServerSearchOrder(0) MtNetCard(UBound(MtNetCard)).DnsString1 = objSWbemObject.DNSServerSearchOrder(1) MtNetCard(UBound(MtNetCard)).MacAdress = objSWbemObject.MacAddress(0) ReDim Preserve MtNetCard(UBound(MtNetCard) + 1) As NetCard Next End Sub

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读