473,395 Members | 2,446 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

DNS Nameserver Lookup

I am using the System.Net namespace to do DNS lookups of a host and return
their IP address. However I haven't figured out how to use the namespace to
take a domain name and find the responsible nameservers. Does anyone have an
idea how to do this?
Jun 12 '07 #1
1 2254
Magnus R,

You have a couple options.

You could use PInvoke for the following signature:
Private Declare Function NetGetDCName Lib "netapi32.dll" (ByVal
strServerName As Object, ByVal strDomainName As Object, ByVal pBuffer As
Long) As Long
You could use the System.Net namespace:

Dim MYIP As System.Net.IPHostEntry =
System.Net.Dns.GetHostEntry(My.Computer.Name)
Dim IPaddress As String = MYIP.AddressList.GetValue(0).ToString
Console.WriteLine(System.Net.Dns.GetHostEntry(IPad dress).HostName)
You could also use the System.Net.NetworkInformation namespace for the long
way around, but more detail. Check out this code:

Imports System.Net
Imports System.Net.NetworkInformation

Public Class NetworkInfo
Public Shared Sub ShowIPAddresses()
Dim computerProperties As IPGlobalProperties =
IPGlobalProperties.GetIPGlobalProperties()
Dim nics() As NetworkInterface =
NetworkInterface.GetAllNetworkInterfaces()
Console.WriteLine("Interface information for {0}.{1} ", _
computerProperties.HostName, computerProperties.DomainName)
If (nics Is Nothing OrElse nics.Length < 1) Then
Console.WriteLine(" No network interfaces found.")
Return
End If

Console.WriteLine(" Number of interfaces .................... :
{0}", nics.Length)
For Each adapter As NetworkInterface In nics
Dim adapterProperties As IPInterfaceProperties =
adapter.GetIPProperties()
Dim dnsServers As IPAddressCollection =
adapterProperties.DnsAddresses

If (Not dnsServers Is Nothing) Then
For Each dns As IPAddress In dnsServers
Console.WriteLine(" DNS Servers
.............................. : {0}", dns.ToString())
Console.WriteLine(" Server Name
........................... : {0}",
System.Net.Dns.GetHostEntry(dns.ToString).HostName )
Next
End If
Next
End Sub
End Class
You could also use the registry:
http://www.java2s.com/Code/CSharp/Ne...DNSServers.htm

Hope this helps,
Steve
"Magnus R" <ro******@hotmail.comwrote in message
news:e5**************@TK2MSFTNGP04.phx.gbl...
>I am using the System.Net namespace to do DNS lookups of a host and return
their IP address. However I haven't figured out how to use the namespace to
take a domain name and find the responsible nameservers. Does anyone have
an idea how to do this?

Jun 13 '07 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

8
by: Lucas Lemmens | last post by:
Dear pythonians, I've been reading/thinking about the famous function call speedup trick where you use a function in the local context to represent a "remoter" function to speed up the 'function...
9
by: Koen | last post by:
Hi all, My application uses a lot of lookup tables. I've splitted the frontend (forms, reports, etc) from the backend (data). The database has around 10 different users. The values in the...
3
by: my-wings | last post by:
I've been reading about how evil Lookup fields in tables are, but I've got to be missing something really basic. I know this subject has been covered before, because I've just spent an hour or two...
3
by: google | last post by:
I have a database with four table. In one of the tables, I use about five lookup fields to get populate their dropdown list. I have read that lookup fields are really bad and may cause problems...
4
by: Wiktor Zychla | last post by:
In my code I have to query the local dns server for some data. however, I have no idea how to get the name of the local DNS server. could anyone point me the right direction? thanks in advance,...
13
by: paul.joseph.davis | last post by:
Hi, I've just had my first encounter with two-phase lookup and I'm scratching my head a bit. The idea behind two phase look up is pretty easy to understand, but I have a case that fails to...
0
by: Chuckk Hubbard | last post by:
The docs say to try to discover the URI on my own if this happens. Could I get a hand doing that? This isn't just something I want to solve on my machine, e.g. by changing my network setup or what...
0
by: Chuckk Hubbard | last post by:
OK, I think I have it. The Manual says to start a Name Server "using the ns command", and I figured out that means using the pyro-ns script. On Mon, Nov 10, 2008 at 10:49 AM, Chuckk Hubbard...
11
by: ianoble | last post by:
I've been trying to piece together various code snippets to create a lookup table inside my xslt without the need for a supplemental xml file. Here is what I have so far. As of now, it does not...
1
by: joeino | last post by:
I want to do a lookup query and append the record to a history table before editing the data. I created a macro to run the lookup query to append the record to history and it works fine. I did the...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.