﻿{"id":820,"date":"2012-05-24T11:08:43","date_gmt":"2012-05-24T03:08:43","guid":{"rendered":"http:\/\/notes.zerobox.org\/?p=820"},"modified":"2012-05-24T11:08:43","modified_gmt":"2012-05-24T03:08:43","slug":"%e9%9d%9e%e5%b8%b8%e7%ae%80%e5%8d%95%e7%9a%84dns%e4%bf%a1%e6%81%af%e6%b3%84%e6%bc%8f%e6%a3%80%e6%b5%8b","status":"publish","type":"post","link":"http:\/\/zerobox.org\/notes\/820.html","title":{"rendered":"\u975e\u5e38\u7b80\u5355\u7684DNS\u4fe1\u606f\u6cc4\u6f0f\u68c0\u6d4b"},"content":{"rendered":"<p>\u6765\u6e90\uff1a<a href=\"http:\/\/hi.baidu.com\/cnqing\/blog\/item\/d21db78e391d50cef11f364a.html\">http:\/\/hi.baidu.com\/cnqing\/blog\/item\/d21db78e391d50cef11f364a.html<\/a><\/p>\n<p>using System;<\/p>\n<p>using System.Collections.Generic;<\/p>\n<p>using System.Text;<\/p>\n<p>using System.Text.RegularExpressions;<\/p>\n<p>using System.Collections;<\/p>\n<p>using System.IO;<\/p>\n<p>using System.Net.Sockets;<\/p>\n<p>class Program<\/p>\n<p>{<\/p>\n<p>static void Main(string[] args)<\/p>\n<p>{<\/p>\n<p>string domain = args[0];<\/p>\n<p>&nbsp;<\/p>\n<p>Whois wis = new Whois();<\/p>\n<p>string result = wis.LookUp(domain);<\/p>\n<p>Regex reg = new Regex(&#8220;name\\\\sserver:(.*)&#8221;, RegexOptions.IgnoreCase);<\/p>\n<p>MatchCollection mcs = reg.Matches(result);<\/p>\n<p>#region \u8f7b\u91cf\u7684DNS\u534f\u8bae\u5305<\/p>\n<p>string name = domain.Substring(0, domain.LastIndexOf(&#8220;.&#8221;));<\/p>\n<p>string suffix = domain.Substring(domain.LastIndexOf(&#8220;.&#8221;) + 1);<\/p>\n<p>byte[] namedata = System.Text.ASCIIEncoding.ASCII.GetBytes(name);<\/p>\n<p>byte[] suffixdata = System.Text.ASCIIEncoding.ASCII.GetBytes(suffix);<\/p>\n<p>int totallen = 14 + namedata.Length + suffixdata.Length + 7;<\/p>\n<p>byte[] dnslisarray = new byte[totallen];<\/p>\n<p>dnslisarray[1] = 0x00;<\/p>\n<p>dnslisarray[2] = 0x01;<\/p>\n<p>dnslisarray[5] = 0x01;<\/p>\n<p>dnslisarray[12] = (byte)(namedata.Length);<\/p>\n<p>namedata.CopyTo(dnslisarray, 13);<\/p>\n<p>dnslisarray[13 + namedata.Length] = (byte)suffixdata.Length;<\/p>\n<p>suffixdata.CopyTo(dnslisarray, 14 + namedata.Length);<\/p>\n<p>&nbsp;<\/p>\n<p>dnslisarray[14 + namedata.Length + suffixdata.Length + 2] = 0xFC;<\/p>\n<p>dnslisarray[14 + namedata.Length + suffixdata.Length + 4] = 0x01;<\/p>\n<p>dnslisarray[14 + namedata.Length + suffixdata.Length + 5] = 0x4D;<\/p>\n<p>dnslisarray[14 + namedata.Length + suffixdata.Length + 6] = 0x53;<\/p>\n<p>&nbsp;<\/p>\n<p>#endregion<\/p>\n<p>bool ishavevul = false;<\/p>\n<p>foreach (Match item in mcs)<\/p>\n<p>{<\/p>\n<p>if (ishavevul) break ;<\/p>\n<p>System.Net.Sockets.TcpClient t = new System.Net.Sockets.TcpClient();<\/p>\n<p>Console.Write(&#8220;checking dns &#8221; + item.Groups[1].Value.Trim());<\/p>\n<p>t.Connect(item.Groups[1].Value.Trim(), 53);<\/p>\n<p>t.Client.Send(new byte[] { 0x0, (byte)totallen });<\/p>\n<p>byte[] buf = new byte[1024];<\/p>\n<p>t.Client.Send(dnslisarray);<\/p>\n<p>buf = new byte[16];<\/p>\n<p>int len = t.Client.Receive(buf);<\/p>\n<p>t.Close();<\/p>\n<p>&nbsp;<\/p>\n<p>if (buf.Length &gt; 8 &amp;&amp; buf[9] &gt; 0)<\/p>\n<p>{<\/p>\n<p>ishavevul = true;<\/p>\n<p>Console.Write(&#8220;\\t find more than &#8221; + buf[9] + &#8221; answers\\r\\n&#8221;);<\/p>\n<p>}<\/p>\n<p>else<\/p>\n<p>{<\/p>\n<p>Console.Write(&#8220;\\t refuse list\\r\\n&#8221;);<\/p>\n<p>}<\/p>\n<p>}<\/p>\n<p>if (!ishavevul)<\/p>\n<p>{<\/p>\n<p>Console.WriteLine( args[0] + &#8221; is safe&#8221;);<\/p>\n<p>}<\/p>\n<p>else<\/p>\n<p>{<\/p>\n<p>Console.WriteLine( args[0] + &#8221; is not safe&#8221;);<\/p>\n<p>}<\/p>\n<p>}<\/p>\n<p>}<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u6765\u6e90\uff1ahttp:\/\/hi.baidu.com\/cnqing\/blog\/item\/ &hellip;<\/p>\n<p class=\"read-more\"><a href=\"http:\/\/zerobox.org\/notes\/820.html\">\u7ee7\u7eed\u9605\u8bfb &raquo;<\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[],"tags":[195],"class_list":["post-820","post","type-post","status-publish","format-standard","hentry","tag-dns"],"views":966,"_links":{"self":[{"href":"http:\/\/zerobox.org\/notes\/wp-json\/wp\/v2\/posts\/820","targetHints":{"allow":["GET"]}}],"collection":[{"href":"http:\/\/zerobox.org\/notes\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/zerobox.org\/notes\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/zerobox.org\/notes\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/zerobox.org\/notes\/wp-json\/wp\/v2\/comments?post=820"}],"version-history":[{"count":0,"href":"http:\/\/zerobox.org\/notes\/wp-json\/wp\/v2\/posts\/820\/revisions"}],"wp:attachment":[{"href":"http:\/\/zerobox.org\/notes\/wp-json\/wp\/v2\/media?parent=820"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/zerobox.org\/notes\/wp-json\/wp\/v2\/categories?post=820"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/zerobox.org\/notes\/wp-json\/wp\/v2\/tags?post=820"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}