I am trying to query a web address and get current non cached results like the root name server and the administrative contact email. Could ye please point me to a guide with sample code on how this can be achieved. Thanks Tommy
Asked
Active
Viewed 753 times
0
-
What is the "root name server"? Contact information for a domain will be found by doing a whois query, but operational information like nameservers of a domain should be found using a DNS query. – Patrick Mevzek Jan 02 '18 at 23:07
1 Answers
1
It looks like you needs WhoIs lookup. DNS lookup does not return administrative email. DNS Lookup returns DNS records such as A, CNAME, MX and TXT records.
For whois query, you will need to query WhoIs data from whois server that the domain belongs to. The following code snippet uses NetworkStream to read WhoIs data of a .com domain:
// Create new socket object
Socket socket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp );
string query = "mydomain.com";
NetworkStream nst;
try
{
IPEndPoint endPoint = new IPEndPoint("whois.internic.net", 43)
socket.Connect(endPoint);
nst = new NetworkStream(socket, true);
string str;
StreamWriter writer = new StreamWriter(nst);
writer.WriteLine(query);
writer.Flush();
StringBuilder builder = new StringBuilder();
StreamReader reader = new StreamReader(nst);
while ((str = reader.ReadLine()) != null)
{
builder.Append(str);
builder.Append(
#if !NETCF
Environment.NewLine
#else
"\r\n"
#endif
);
}
result = builder.ToString();
}
finally
{
if (nst != null)
nst.Close();
socket.Close();
}
-
For each TLD you should better use the registry TLD whois server. – Patrick Mevzek Jan 02 '18 at 23:06