<p>I want to get whois information of a domain name from my c#/java programs. Is there a simple way to do this? </p>

[{'answer_id': 53631, 'author': 'Thomas', 'author_id': 4980, 'author_profile': 'https://Stackoverflow.com/users/4980', 'pm_score': 2, 'selected': False, 'text': '<p>I think, the easiest way is a socket connection to a whois server on port 43. Send the domainname followed by a newline and read the response.</p>\n'}, {'answer_id': 53632, 'author': 'Chris Bunch', 'author_id': 422, 'author_profile': 'https://Stackoverflow.com/users/422', 'pm_score': -1, 'selected': False, 'text': '<p>Here\'s the Java solution, which just opens up a shell and runs <code>whois</code>:</p>\n\n<pre><code>import java.io.*;\nimport java.util.*;\n\npublic class ExecTest2 {\n    public static void main(String[] args) throws IOException {\n        Process result = Runtime.getRuntime().exec("whois stackoverflow.com");\n\n        BufferedReader output = new BufferedReader(new InputStreamReader(result.getInputStream()));\n        StringBuffer outputSB = new StringBuffer(40000);\n        String s = null;\n\n        while ((s = output.readLine()) != null) {\n            outputSB.append(s + "\\n");\n            System.out.println(s);\n        }\n\n        String whoisStr = output.toString();\n    }\n}\n</code></pre>\n'}, {'answer_id': 177758, 'author': 'Alnitak', 'author_id': 6782, 'author_profile': 'https://Stackoverflow.com/users/6782', 'pm_score': 2, 'selected': False, 'text': '<p>Thomas\' answer will only work if you know <em>which</em> &quot;whois&quot; server to connect to.</p>\n<p>There are many different ways of finding that out, but none (AFAIK) that works uniformly for every domain registry.</p>\n<p>Some domain names support an <code>SRV</code> record for the <code>_nicname._tcp</code> service in the DNS, but there are issues with that because there\'s no accepted standard yet on how to prevent a subdomain from serving up <code>SRV</code> records which override those of the official registry (see <a href="https://datatracker.ietf.org/doc/html/draft-sanz-whois-srv-00" rel="nofollow noreferrer">https://datatracker.ietf.org/doc/html/draft-sanz-whois-srv-00</a>).</p>\n<p>For many TLDs it\'s possible to send your query to <code>&lt;tld&gt;.whois-servers.net</code>.  This actually works quite well, but beware that it won\'t work in all cases where there are officially delegated second level domains.</p>\n<p>For example in <code>.uk</code> there are several official sub-domains, but only some of them are run by the <code>.uk</code> registry and the others have their own WHOIS services and those aren\'t in the <code>whois-servers.net</code> database.</p>\n<p>Confusingly there are also &quot;unofficial&quot; registries, such as <code>.uk.com</code>, which <em>are</em> in the <code>whois-servers.net</code> database.</p>\n<p>p.s. the official End-Of-Line delimiter in WHOIS, as with most IETF protocols is <code>CRLF</code>, not just <code>LF</code>.</p>\n'}, {'answer_id': 923873, 'author': 'Jeff', 'author_id': 105756, 'author_profile': 'https://Stackoverflow.com/users/105756', 'pm_score': 2, 'selected': False, 'text': '<p>I found some web services that offer this information.  This one is free and worked great for me.  <a href="http://www.webservicex.net/whois.asmx?op=GetWhoIS" rel="nofollow noreferrer">http://www.webservicex.net/whois.asmx?op=GetWhoIS</a></p>\n'}, {'answer_id': 1067587, 'author': 'Andrew Shepherd', 'author_id': 25216, 'author_profile': 'https://Stackoverflow.com/users/25216', 'pm_score': 4, 'selected': True, 'text': '<p>I found a perfect C# example on dotnet-snippets.com (<em>which doesn\'t exist anymore</em>). </p>\n\n<p>It\'s 11 lines of code to copy and paste straight into your own application.</p>\n\n<pre><code>/// &lt;summary&gt;\n/// Gets the whois information.\n/// &lt;/summary&gt;\n/// &lt;param name="whoisServer"&gt;The whois server.&lt;/param&gt;\n/// &lt;param name="url"&gt;The URL.&lt;/param&gt;\n/// &lt;returns&gt;&lt;/returns&gt;\nprivate string GetWhoisInformation(string whoisServer, string url)\n{\n    StringBuilder stringBuilderResult = new StringBuilder();\n    TcpClient tcpClinetWhois = new TcpClient(whoisServer, 43);\n    NetworkStream networkStreamWhois = tcpClinetWhois.GetStream();\n    BufferedStream bufferedStreamWhois = new BufferedStream(networkStreamWhois);\n    StreamWriter streamWriter = new StreamWriter(bufferedStreamWhois);\n\n    streamWriter.WriteLine(url);\n    streamWriter.Flush();\n\n    StreamReader streamReaderReceive = new StreamReader(bufferedStreamWhois);\n\n    while (!streamReaderReceive.EndOfStream)\n        stringBuilderResult.AppendLine(streamReaderReceive.ReadLine());\n\n    return stringBuilderResult.ToString();\n}\n</code></pre>\n'}, {'answer_id': 16179401, 'author': 'user2313093', 'author_id': 2313093, 'author_profile': 'https://Stackoverflow.com/users/2313093', 'pm_score': 2, 'selected': False, 'text': "<p>I found a perfect C# example here. It's 11 lines of code to copy and paste straight into your own application. BUT FIRST you should add some using statements to ensure that the dispose methods are properly called to prevent memory leaks:</p>\n\n<pre><code>StringBuilder stringBuilderResult = new StringBuilder();\nusing(TcpClient tcpClinetWhois = new TcpClient(whoIsServer, 43))\n{\n   using(NetworkStream networkStreamWhois = tcpClinetWhois.GetStream())\n   {\n      using(BufferedStream bufferedStreamWhois = new BufferedStream(networkStreamWhois))\n      {\n         using(StreamWriter streamWriter = new StreamWriter(bufferedStreamWhois))\n         {\n            streamWriter.WriteLine(url);\n            streamWriter.Flush();\n            using (StreamReader streamReaderReceive = new StreamReader(bufferedStreamWhois))\n            {\n               while (!streamReaderReceive.EndOfStream) stringBuilderResult.AppendLine(streamReaderReceive.ReadLine());\n            }\n         }\n      }\n   }\n}\n</code></pre>\n"}, {'answer_id': 72093332, 'author': 'Erman Çetin', 'author_id': 4819851, 'author_profile': 'https://Stackoverflow.com/users/4819851', 'pm_score': 0, 'selected': False, 'text': '<p>if you add <code>leaveOpen: true</code> to the <code>StreamWriter</code> and <code>StreamReader</code> constructors. You will not get &quot;Cannot access a closed stream&quot; exception</p>\n<pre><code>var stringBuilderResult = new StringBuilder();\n\nusing (var tcpClinetWhois = new TcpClient(whoIsServer, 43))\nusing (var networkStreamWhois = tcpClinetWhois.GetStream())\nusing (var bufferedStreamWhois = new BufferedStream(networkStreamWhois))\nusing (var streamWriter = new StreamWriter(networkStreamWhois, leaveOpen: true))\n{\n    streamWriter.WriteLine(url);\n    streamWriter.Flush();\n\n    using (var streamReaderReceive = new StreamReader(networkStreamWhois, leaveOpen: true))\n    {\n        while (!streamReaderReceive.EndOfStream)\n        {\n            stringBuilderResult.AppendLine(streamReaderReceive.ReadLine());\n        }\n    }\n}\n</code></pre>\n'}]
['https://Stackoverflow.com/questions/53623', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/184/']