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
 
Back
Top