Auto detect DNS Server Ip

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • beyrself
    New Member
    • Dec 2008
    • 6

    Auto detect DNS Server Ip

    Hi all, I need help in retriving the DNS server ip of my computer. But with my codes i only manage to the IP address of my computer.

    Dim IPAddress As IPAddress = Dns.GetHostEntr y(Dns.GetHostNa me).AddressList (1)
    Dim strIPAddress As String = IPAddress.ToStr ing
    TextBox3.Text = strIPAddress

    please help thanks!
  • shrimant
    New Member
    • Sep 2007
    • 48

    #2
    Code:
    Sub Main()
        Dim Output
        Set objShell = CreateObject("WScript.Shell")
        Set objExecObject = objShell.Exec("%comspec% /c ipconfig /all")
        Output = objExecObject.StdOut.ReadAll()
        Set objExecObject = Nothing
        DNS = Trim(Replace(Mid(Output, InStr(InStr(1, Output, "DNS Servers"), Output, ":") + 1, 15), Chr(13), ""))
    End Sub
    Use the above code the Variable OUTPUT shall have you the following result as a string, all you need to do is ..Parse the DNS server IP address, in the above code the Variable DNS shall have the Primary DNS's IP address. Kind of crude but guranteed to work.

    Code:
    Description . . . . . . . . . . . : Intel(R) 82566DM-2 Gigabit Network Connection
    
            Physical Address. . . . . . . . . : 00-1E-4F-CA-B5-3F
    
            Dhcp Enabled. . . . . . . . . . . : No
    
            IP Address. . . . . . . . . . . . : 62.121.164.55
    
            Subnet Mask . . . . . . . . . . . : 255.255.255.0
    
            Default Gateway . . . . . . . . . : 62.121.164.34
    
            DNS Servers . . . . . . . . . . . : 62.121.164.7
    
                                                62.121.164.21
    
            Primary WINS Server . . . . . . . : 62.121.164.2

    Comment

    Working...