Last active
August 29, 2015 14:04
-
-
Save shutingrz/74e6cc869307cf7a7f58 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/usr/local/bin/ruby | |
| # -*- coding: utf-8 -*- | |
| require 'cgi' | |
| require 'resolv' | |
| cgi = CGI.new | |
| record = Array.new | |
| host="" | |
| type="" | |
| t="a" | |
| host = cgi["host"] | |
| type = cgi["type"] | |
| host = CGI.escapeHTML(host) | |
| head = <<"EOS" | |
| <html> | |
| <head> | |
| <title>resolver.rb</title> | |
| <meta http-equiv="Content-Type" content="text/html;charset=UTF-8" /> | |
| </head> | |
| <body> | |
| Ruby Resolv::DNS with sakura VPS(133.242.0.3)<br> | |
| <form method="POST" action="./resolver.rb"> | |
| <input name="host" type="text" value="#{host}"> | |
| <select name="type" size=1> | |
| <option value="a">A</option> | |
| <option value="aaaa">AAAA</option> | |
| <option value="ns">NS</option> | |
| <option value="mx">MX</option> | |
| <option value="ptr">PTR</option> | |
| <option value="soa">SOA</option> | |
| <option value="txt">TXT</option> | |
| </select><br> | |
| <input type="submit" value="Send"><br> | |
| </form> | |
| <hr> | |
| EOS | |
| print "Content-type: text/html\n\n" | |
| puts head | |
| puts ";; QUESTION SECTION:<br>" | |
| puts ";; #{host} IN " | |
| case type | |
| when "a" then | |
| puts "A<br><br>" | |
| puts ";; ANSWER SECTION:<br>" | |
| Resolv::DNS.new.getresources(host, Resolv::DNS::Resource::IN::A).collect do |r| | |
| record << "#{host} #{r.ttl} IN A #{r.address}" | |
| end | |
| when "aaaa" then | |
| puts "AAAA<br><br>" | |
| puts ";; ANSWER SECTION:<br>" | |
| Resolv::DNS.new.getresources(host, Resolv::DNS::Resource::IN::AAAA).collect do |r| | |
| record << "#{host} #{r.ttl} IN AAAA #{r.address}" | |
| end | |
| when "ns" then | |
| puts "NS<br><br>" | |
| puts ";; ANSWER SECTION:<br>" | |
| Resolv::DNS.new.getresources(host, Resolv::DNS::Resource::IN::NS).collect do |r| | |
| record << "#{host} #{r.ttl} IN NS #{r.name}" | |
| end | |
| when "mx" then | |
| puts "MX<br><br>" | |
| puts ";; ANSWER SECTION:<br>" | |
| Resolv::DNS.new.getresources(host, Resolv::DNS::Resource::IN::MX).collect do |r| | |
| record << "#{host} #{r.ttl} IN MX #{r.preference} #{r.exchange}" | |
| end | |
| when "ptr" then | |
| puts "PTR<br><br>" | |
| puts ";; ANSWER SECTION:<br>" | |
| Resolv::DNS.new.getresources(host, Resolv::DNS::Resource::IN::PTR).collect do |r| | |
| record << "#{host} #{r.ttl} IN PTR #{r.name}" | |
| end | |
| when "soa" then | |
| puts "SOA<br><br>" | |
| puts ";; ANSWER SECTION:<br>" | |
| Resolv::DNS.new.getresources(host, Resolv::DNS::Resource::IN::SOA).collect do |r| | |
| record << "#{host} #{r.ttl} IN PTR #{r.mname} #{r.rname} #{r.serial} #{r.refresh} #{r.retry} #{r.expire} #{r.minimum}" | |
| end | |
| when "txt" then | |
| puts "TXT<br><br>" | |
| puts ";; ANSWER SECTION:<br>" | |
| Resolv::DNS.new.getresources(host, Resolv::DNS::Resource::IN::TXT).collect do |r| | |
| record << "#{host} #{r.ttl} IN TXT #{r.strings}" | |
| end | |
| else | |
| puts "A<br><br>" | |
| puts ";; ANSWER SECTION:<br>" | |
| Resolv::DNS.new.getresources(host, Resolv::DNS::Resource::IN::A).collect do |r| | |
| record << "#{host} #{r.ttl} IN A #{r.address}" | |
| end | |
| end | |
| record.each do |r| | |
| puts CGI.escapeHTML(r) + "<br>" | |
| end | |
| if(record == []) then | |
| puts "No records." | |
| end | |
| puts "\n </body>\n</html>" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment