Copy DNS resolution code

Source: Internet
Author: User

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 ;}}}} 

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.