How to Get Local Machine's DNS IP Address

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I'm trying to programmatically determine the local machine's DNS IP address
(i.e. the IP address of the DNS server). Can anyone steer me in the right
direction?

Thanks!
 
Yes! That's exactly the nudge that I needed. :)

Here's the code incase anyone else is interested:

imports System.Management

Sub Main()
Dim mc As ManagementClass = New
ManagementClass("Win32_NetworkAdapterConfiguration")
Dim mo As ManagementObject
Dim moc As ManagementObjectCollection = mc.GetInstances()
Dim dns As String()
Dim i As Integer
For Each mo In moc

If CType(mo("ipEnabled"), Boolean) Then
Console.WriteLine(mo("Caption"))
dns = CType(mo("DNSServerSearchOrder"), String())
For i = 0 To dns.GetUpperBound(0)
Console.WriteLine(dns(i))
Next
End If
Next
End Sub
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top