How to get domain information in my program?

I want to get whois information about a domain name from my C # / java programs. Is there an easy way to do this?

+3
source share
6 answers

I think the easiest way is to connect the socket to the whois server on port 43. Send the domain name followed by a new line and read the answer.

+4
source

I found the perfect C # example here.

These are 11 lines of code to copy and paste directly into your own application.

/// <summary>
/// Gets the whois information.
/// </summary>
/// <param name="whoisServer">The whois server.</param>
/// <param name="url">The URL.</param>
/// <returns></returns>
private string GetWhoisInformation(string whoisServer, string url)
{
    StringBuilder stringBuilderResult = new StringBuilder();
    TcpClient tcpClinetWhois = new TcpClient(whoisServer, 43);
    NetworkStream networkStreamWhois = tcpClinetWhois.GetStream();
    BufferedStream bufferedStreamWhois = new BufferedStream(networkStreamWhois);
    StreamWriter streamWriter = new StreamWriter(bufferedStreamWhois);

    streamWriter.WriteLine(url);
    streamWriter.Flush();

    StreamReader streamReaderReceive = new StreamReader(bufferedStreamWhois);

    while (!streamReaderReceive.EndOfStream)
        stringBuilderResult.AppendLine(streamReaderReceive.ReadLine());

    return stringBuilderResult.ToString();
}
+4
source

, , "whois" .

, (AFAIK), .

SRV _nicname._tcp DNS, , , SRV, (. http://tools.ietf.org/html/draft-sanz-whois-srv-00).

TLD <tld>.whois-servers.net. , , , .

, .uk , .uk, WHOIS, , whois-servers.net.

"" , .uk.com, whois-servers.net.

p.s. End-Of-Line WHOIS, IETF, CRLF, LF.

+2

#. 11 . BUT FIRST , , :

StringBuilder stringBuilderResult = new StringBuilder();
using(TcpClient tcpClinetWhois = new TcpClient(whoIsServer, 43))
{
   using(NetworkStream networkStreamWhois = tcpClinetWhois.GetStream())
   {
      using(BufferedStream bufferedStreamWhois = new BufferedStream(networkStreamWhois))
      {
         using(StreamWriter streamWriter = new StreamWriter(bufferedStreamWhois))
         {
            streamWriter.WriteLine(url);
            streamWriter.Flush();
            using (StreamReader streamReaderReceive = new StreamReader(bufferedStreamWhois))
            {
               while (!streamReaderReceive.EndOfStream) stringBuilderResult.AppendLine(streamReaderReceive.ReadLine());
            }
         }
      }
   }
}
+2

Here's a Java solution that simply opens a shell and runs whois:

import java.io.*;
import java.util.*;

public class ExecTest2 {
    public static void main(String[] args) throws IOException {
        Process result = Runtime.getRuntime().exec("whois stackoverflow.com");

        BufferedReader output = new BufferedReader(new InputStreamReader(result.getInputStream()));
        StringBuffer outputSB = new StringBuffer(40000);
        String s = null;

        while ((s = output.readLine()) != null) {
            outputSB.append(s + "\n");
            System.out.println(s);
        }

        String whoisStr = output.toString();
    }
}
-3
source

Source: https://habr.com/ru/post/1696766/


All Articles