Obtain Nic information using VB6

Source: Internet
Author: User

You need to use VB6 to read network card network management information and set it. So I found a piece of code that uses WMI's system query method to loop through all network adapters and obtain information.

Of course, you can add judgment and processing.

 

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 commandementclick ()
Dim I as long
For I = lbound (mtnetcard) to ubound (mtnetcard)-1
Text1 = text1 & "Nic:" & mtnetcard (I). Name & vbnewline
Text1 = text1 & "IP Address:" & mtnetcard (I). ipadress & vbnewline
Text1 = text1 & "subnet mask:" & mtnetcard (I). ipsubnets & vbnewline
Text1 = text1 & "Gateway:" & 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' Add a NIC with the TCP/IP protocol installed on the local machine
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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.