Permalink
Browse files

checkpoint

  • Loading branch information...
jpf committed Jul 9, 2009
1 parent 5530c31 commit 24aeadccbba278a032aa9d486083019b8ac48cf1
View
10 TODO
@@ -1,9 +1,9 @@
# paid for:
-# x registrar
-# x hosting
-# x dns hosting
-# x email hosting
-# x ssl certificate
+# x whois.registrar
+# x dns.a (owner)
+# x dns.ns (owner)
+# x dns.mx (owner)
+# x ssl.issuer
#
# made decision:
# - [dns ] outsourced email?
View
@@ -1,258 +0,0 @@
-#!/usr/bin/env ruby
-# paid for:
-# x registrar
-# x hosting
-# x dns hosting
-# x email hosting
-# x ssl certificate
-#
-# made decision:
-# - [dns ] outsourced email?
-# x [dns ] spf?
-# x [dns ] ttl's on DNS?
-# - [ssl ] ssl expires
-# - [whoi] domain expires
-# - [as ] different ASes
-# - [as ] multi-homing dns?
-# - [as ] all services in same as?
-# - [curl] valid xhtml?
-# - [curl] frontend type
-# - [nmap] port scan
-# - [dns+] check for *.records
-
-require 'pp'
-
-#TODO: make this into a gem!
-def seconds_to_english(seconds)
- time = [
- [ :year , 31556926 ],
- [ :month , 2629743 ],
- [ :week , 604800 ],
- [ :day , 86400 ],
- [ :hour , 3600 ],
- [ :minute , 60 ],
- [ :second , 1 ],
- ]
- seconds = seconds.to_i
- out = []
- time.each { |period,length|
- count = seconds / length
- if count > 0
- seconds -= count * length
-
- string = "#{count} "
- string << period.to_s
- string << 's' if count > 1
- out.push(string)
- end
- }
- out.join(', ')
-end
-
-
-class DomainInfo
- def initialize(host)
- @host = host
- @whois = `sleep 3; whois #{host}`.split("\n")
- @dns = {}
- [:mx, :ns, :a, :txt].each { |type|
- @dns[type] = `dig #{host} -t #{type.to_s}`
- }
- @ssl = `echo '' | openssl s_client -connect #{host}:443 2>&1`
- end
- attr_accessor :whois, :dns, :ssl
-end
-
-class Domain
- def initialize(host)
- @host = host.downcase
- filename = "cache/cache-#{host}.cache"
- if File.exists?(filename)
- @info = open(filename) { |f| Marshal.load(f) }
- else
- @info = DomainInfo.new(host)
- open(filename, "w") { |f| Marshal.dump(@info, f) }
- end
- end
- def registrar
- self.info.whois.grep(/Registrar:/).to_s.split(': ')[1]
- end
- def mx
- method_missing(:mx).map { |rv|
- rv[:host] = Hostname.new(rv[:answer].split(' ')[1])
- rv
- }
- end
- def ssl_issuer
- begin
- self.info.ssl.split("\n").grep(/^issuer=/).to_s.match(/O=([^\/]+)/)[1]
- rescue
- 'none'
- end
- end
- def method_missing(type)
- lookup = [:query,:ttl,:cl,:type,:answer]
- h = Hash[]
- self.info.dns[type].split("\n").grep(/^[^;]/).map { |line|
- rv = Hash[*lookup.zip(line.gsub("\t\t","\t").split("\t")).flatten]
- rv[:host] = Hostname.new(rv[:answer])
- rv
- }
- end
- attr_accessor :host, :info
-end
-
-#TODO: abstract this
-class Hostname
- def initialize(host)
- @host = host
- end
- def method_missing(type)
- @host
- end
- def sld
- @host.split('.')[-2..-1].join('.').downcase
- end
- def ip
- `dig #{@host} a +short`.chomp
- end
- def org
- filename = "cache/#{@host}.cache"
- if File.exists?(filename)
- whois = open(filename) { |f| Marshal.load(f) }
- else
- whois = `sleep 3; whois #{@host}`.split("\n")
- open(filename, "w") { |f| Marshal.dump(whois, f) }
- end
-
- begin
- whois.grep(/^OrgName:/).to_s.match(/OrgName:\s+(.*)/)[1]
- rescue
- `./geoiplookup -f GeoIPOrg.dat #{@host}`.chomp.split(': ')[1]
- end
- end
-end
-
-class PaidFor
- def initialize(domain)
- @domain = domain
- end
- def registrar
- self.to_symbol(@domain.registrar)
- end
- def ssl_issuer
- self.to_symbol(@domain.ssl_issuer)
- end
- def hosting
- @domain.a.map {|rv| self.to_symbol(rv[:host].org) }.uniq
- end
- def dns_hosting
- @domain.ns.map { |rv| self.to_symbol(rv[:host].sld) }.uniq
- end
- def email_hosting
- @domain.mx.map { |rv| self.to_symbol(rv[:host].sld) }.uniq
- end
- def to_symbol(name)
- lookup = {
- '1 & 1 internet ag' => '1and1', # 2
- '1and1.com' => '1and1', # 1
- 'akam.net' => 'akami', # 2
- 'akamai technologies' => 'akami', # 1
- 'amazon.com' => 'amazon', #13
- 'amazon.com, inc.' => 'amazon',
- 'comodo ca limited' => 'comodo', # 2
- 'digicert inc' => 'digicert', # 3
- 'domaincontrol.com' => 'godaddy', #11
- 'dotster, inc. registrar' => '', # 2
- 'dstr acquisition pa i, llc dba domainbank.com registrar' => '', # 1
- 'easydns technologies, inc.' => 'easydns', # 1
- 'easydns.com' => 'easydns', # 3
- 'easydns.org' => 'easydns', # 1
- 'emailsrvr.com' => 'enom', # 1
- 'enom, inc.' => 'enom', # 7
- 'enom, incorporated' => 'enom', # 1
- 'equifax secure inc.' => 'equifax', # 5
- 'gandi sas' => 'gandi', # 1
- 'gandi.net' => 'gandi', # 2
- 'godaddy.com' => 'godaddy', # 3
- 'godaddy.com, inc.' => 'godaddy', #59
- 'google.com' => 'google', #45
- 'googlemail.com' => 'google', #44
- 'mailhop.org' => 'dyninc', # 1
- 'messagingengine.com' => 'enom', # 2
- 'mydyndns.org' => 'dyninc', # 5
- 'name-services.com' => 'enom', # 2
- 'nettica.com' => 'nettica', # 3
- 'network solutions, llc.' => 'netsol', # 2
- 'pair networks' => 'pair', # 2
- 'pair.com' => 'pair', # 2
- 'rackspace.com' => 'rackspace', # 2
- 'registrar-servers.com' => 'enom', # 1
- 'secureserver.net' => 'godaddy', # 1
- 'slicehost llc' => 'slicehost', #13
- 'slicehost.net' => 'slicehost', #11
- 'softlayer corporate c' => 'softlayer', # 1
- 'softlayer technologies' => 'softlayer', # 1
- 'softlayer.com' => 'softlayer', # 5
- 'softlayer technologies inc.' => 'softlayer',
- 'ultradns.info' => 'ultradns', # 1
- 'ultradns.net' => 'ultradns', # 1
- 'ultradns.org' => 'ultradns', # 1
- 'verisign trust network' => 'verisign', # 1
- 'verisign, inc.' => 'verisign', # 4
- 'wild west domains, inc.' => 'godaddy', #1
- }
-
- return 'empty' unless (defined? name)
- return 'empty' if name.nil?
- lcname = name.downcase
- return 'self' if lcname == @domain.host
- return lookup[lcname] if lookup[lcname]
- name
- end
- def to_text
- self.public_methods(all=false).each { |name|
- next if name.match(/^to_/)
- print "#{name} = "
- pp self.send(name.intern)
- }
- end
- def to_text_simple
- self.public_methods(all=false).each { |name|
- next if name.match(/^to_/)
- print self.send(name.intern).to_a.join("\n")
- }
- end
-end
-
-class Decision
- def initialize(domain)
- @domain = domain
- end
- def spf
- @domain.txt.map { |record| record[:answer].gsub('"','').grep(/^v=spf/) }.flatten
- end
- def ttls
- rv = {}
- [:ns,:a,:mx,:txt].each { |type|
- rv[type] = @domain.send(type).map { |record| seconds_to_english(record[:ttl]) }.uniq
- }
- rv
- end
- def to_text
- self.public_methods(all=false).each { |name|
- next if name.match(/^to_/)
- print "#{name} = "
- pp self.send(name.intern)
- }
- end
-end
-
-host = Hostname.new(ARGV[0])
-print "host = #{host.name}\n"
-domain = Domain.new(host.sld)
-paidfor = PaidFor.new(domain)
-decision = Decision.new(domain)
-paidfor.to_text
-decision.to_text
-print "\n"
View
No changes.
View
@@ -3,27 +3,67 @@ class DNSType
def initialize(input)
@input = input
end
+ # Helper for the :mx method
+ def priority
+ return '' unless @input[:type] == 'MX'
+ @input[:answer].split(' ')[0]
+ end
+ # Helper for the :mx method
+ def host
+ return '' unless @input[:type] == 'MX'
+ @input[:answer].split(' ')[1]
+ end
def method_missing(type)
- @input.map { |a| a[type] }.sort
+ begin
+ @input[type] ||= ''
+ rescue
+ ''
+ end
end
end
class DNSQuery
def initialize(input)
- lookup = [:query,:ttl,:cl,:type,:answer]
- @query = input.grep(/^[^;]/).map do |line|
- Hash[*lookup.zip(line.gsub("\t\t","\t").split("\t")).flatten]
+ @lookup = [:query,:ttl,:cl,:type,:answer]
+ begin
+ @query = input.grep(/^[^;]/).map do |line|
+ Hash[*@lookup.zip(line.gsub("\t\t","\t").split("\t")).flatten]
+ end
+ rescue
+ @query = Hash[]
+ end
+
+ end
+ def spf
+ rv = @query.map{|record|
+ record if record[:type] == 'TXT'
+ }.compact
+ if rv.empty?
+ [DNSType.new(nil)]
+ else
+ rv.map { |record| DNSType.new(record) }
end
end
def method_missing(type)
- rv = @query.map { |record| if record[:type] == type.to_s.upcase; record; else; nil; end }.compact
- DNSType.new(rv)
+ rv = @query.sort{|a,b| a[:answer] <=> b[:answer]}.map { |record|
+ record if record[:type] == type.to_s.upcase
+ }.compact
+ if rv.empty?
+ [DNSType.new(nil)]
+ else
+ rv.map { |record| DNSType.new(record) }
+ end
end
+
end
class DNS
def parse(data)
- @data = data.split("\n")
+ begin
+ @data = data.split("\n")
+ rescue
+ @data = Array.new()
+ end
end
def method_missing(type)
query = DNSQuery.new(@data)
@@ -4,6 +4,10 @@ def parse(data)
@data = data.split("\n")
end
def ca
- @data.grep(/^ 1 s:/).to_s.match(/O=([^\/]+)\/[A-Z]/)[1]
+ begin
+ @data.grep(/^issuer=/).to_s.match(/O=([^\/]+)\/[A-Z]/)[1]
+ rescue
+ 'Unknown'
+ end
end
end
@@ -1,9 +1,13 @@
class Whois
def parse(data)
- @data = data.split("\n")
+ @data = data.to_s.split("\n")
end
def registrar
- @data.grep(/Registrar:/).to_s.split(': ')[1]
+ begin
+ @data.grep(/Registrar:/).to_s.split(': ')[1] ||= 'Unknown'
+ rescue
+ 'Unknown'
+ end
end
end
Oops, something went wrong.

0 comments on commit 24aeadc

Please sign in to comment.