Temporary memo
View code
Using System; Using System. Collections. Generic; Using System. componentmodel; Using System. Data; Using System. drawing; Using System. LINQ; Using System. text; Using System. Windows. forms; Using Arsoft. Tools. net. DNS; Using System. net; Using System. diagnostics; Namespace Uset { Public Partial Class Form1: FORM { Public Form1 () {initializecomponent ();} Private Void Button#click ( Object Sender, eventargs e) {trace. traceerror ( " Xxx " ); VaR Dnsserverip = IPaddress. parse ( " 192.168.1.30 " ); Dnsclient dsnclient = New Dnsclient (dnsserverip, 3000 ); Stopwatch SW = New Stopwatch (); Sw. Start (); console. writeline ( " -------- Response ---------- " ); VaR R = Dsnclient. Resolve (textbox1.text ); If (R! =Null ){ Foreach ( VaR It In R. answerrecords ){ VaR AR = it As Arecord; If (Ar! = Null ) Console. writeline (AR. Address. tostring () ;}} Sw. Stop (); console. writeline (SW. elapsedmilliseconds );} Private Dnsserver server { Get ; Set ;} Private Void Button2_click ( Object Sender, eventargs e) {dnsserver = New Dnsserver ( 10 , 10 , Processquery); server = Dnsserver; dnsserver. Start ();} Private Void Button3_click ( Object Sender, eventargs e ){ If (Server! = Null ) Server. Stop ();} Private Static Lazy <dnsclient> lazyclient =New Lazy <dnsclient> () => dnsclient. Default, True ); Private Static Dnsmessagebase processquery (dnsmessagebase message, IPaddress clientaddress, system. net. sockets. protocoltype protocol) {message. isquery = False ; Dnsmessage Query = Message As Dnsmessage; // The official example document does not show the IP address of the DNS request initiator. I have added it here. Console. writeline ( " Client address: {0} " , Clientaddress. tostring (); console. writeline ( " Query. Questions. Count: {0} " , Query. Questions. Count); console. writeline ( " Query. Questions. tostring (): {0} " , Query. Questions. tostring (); console. writeline ( " Query. Questions [0]. tostring (): {0} " , Query. Questions [ 0 ]. Tostring (); console. writeline ( " Query. Questions [0]. GetType (): {0} " , Query. Questions [ 0 ]. GetType (). tostring (); console. writeline ( " Query. Questions [0]. Name: {0} " , Query. Questions [0 ]. Name. tostring (); console. writeline ( " Query. Questions [0]. recordtype: {0} " , Query. Questions [ 0 ]. Recordtype. tostring (); console. writeline ( " Query. Questions [0]. recordclass {0} " , Query. Questions [ 0 ]. Recordclass. tostring ()); // Add your own Parsing If (Query. Questions [ 0 ]. Name. Contains ( " Xxx " ) {Query. answerrecords. Add ( New Arecord ( "" , 3600 , IPaddress. parse ( " 192.168.1.94 " ); Message. returncode =Returncode. noerror; Return Message ;} Else { VaR R = lazyclient. value. Resolve (query. Questions [ 0 ]. Name ); If (R! = Null ){ Foreach ( VaR ItIn R. answerrecords ){ VaR AR = it As Arecord; If (Ar! = Null ) {Query. answerrecords. Add (AR) ;}} message. returncode = Returncode. noerror ;} Return Message ;}}}}