Skip to content
This repository

New GoDaddy parser and fix issue 103 #105

Closed
wants to merge 4 commits into from

2 participants

pmyteh Simone Carletti
pmyteh
pmyteh commented July 31, 2011

I've written a simple parser for responses from whois.godaddy.com, the single largest .com registry. Their format for addresses is depressingly irregular (may be missing the organization and/or telephone/fax number lines, without the helpful field: data format given by some other registries) but it works pretty well and adds parseability to ~30% of all .coms.

Issue #103 is also fixed by a separate small commit.

Thanks,
Tom

Simone Carletti
Owner

Hi Tom,

thank you very much for the parser. Unfortunately, I cannot merge the pull request without a test suite.
Would it be possible to provide it?

Creating a test suite for a parser is just easy as extracting some fixtures and creating a .expected file.
See for example bfbd27b or 8218ebb

Simone Carletti
Owner

I merged your fix for issue #103

pmyteh

Sorry - I'm rather new to this. I'll have a look and put something together.

pmyteh

Hope that's sufficient. Like whois.markmonitor.com, the server really shouldn't be queried unless the domain is registered. If there's something else I'm missing, do let me know: I'd like to get this right.

Simone Carletti
Owner

Thanks @pmyteh. Once you create the tests, you should also run

$ rake genspec:parser

to generate the test suites and then run

$ rake

to execute them. I executed the test suite and one test fails.

1) Whois::Record::Parser::WhoisGodaddyCom status_registered.expected#registrant_contacts 
   Failure/Error: @parser.registrant_contacts[0].email.should        == ""
     expected: ""
          got: nil (using ==)
   # ./spec/whois/record/parser/responses/whois.godaddy.com/status_registered_spec.rb:80:in `block (3 levels) in <top (required)>'

The rest of the patch is ok for me.

Simone Carletti weppos closed this in fae71f9 August 25, 2011
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
This page is out of date. Refresh to see the latest.
130  lib/whois/record/parser/whois.godaddy.com.rb
... ...
@@ -0,0 +1,130 @@
  1
+#--
  2
+# Ruby Whois
  3
+#
  4
+# An intelligent pure Ruby WHOIS client and parser.
  5
+#
  6
+# Copyright (c) 2009-2011 Simone Carletti <weppos@weppos.net>
  7
+#++
  8
+
  9
+
  10
+require 'whois/record/parser/base'
  11
+
  12
+
  13
+module Whois
  14
+  class Record
  15
+    class Parser
  16
+
  17
+      #
  18
+      # = whois.godaddy.com parser
  19
+      #
  20
+      # Parser for the whois.godaddy.com server.
  21
+      # Contributed by Tom Nicholls <tom.nicholls@oii.ox.ac.uk>
  22
+      #
  23
+      #
  24
+      # NOTE: This parser is just a stub and provides only a few basic methods
  25
+      # to check for domain availability and get domain status.
  26
+      # Please consider to contribute implementing missing methods.
  27
+      # See WhoisNicIt parser for an explanation of all available methods
  28
+      # and examples.
  29
+      #
  30
+
  31
+      class WhoisGodaddyCom < Base
  32
+
  33
+        property_not_supported :status
  34
+
  35
+        # The server seems to provide only information for registered domains
  36
+        property_supported :available? do
  37
+          false
  38
+        end
  39
+
  40
+        property_supported :registered? do
  41
+          !available?
  42
+        end
  43
+
  44
+        property_supported :created_on do
  45
+          if content_for_scanner =~ /Created on: (.+)\n/
  46
+            Time.parse($1)
  47
+          end
  48
+        end
  49
+
  50
+        property_supported :updated_on do
  51
+          if content_for_scanner =~ /Last Updated on: (.+)\n/
  52
+            Time.parse($1)
  53
+          end
  54
+        end
  55
+
  56
+        property_supported :expires_on do
  57
+          if content_for_scanner =~ /Expires on: (.+)\n/
  58
+            Time.parse($1)
  59
+          end
  60
+        end
  61
+
  62
+
  63
+        property_supported :registrar do
  64
+          Record::Registrar.new(
  65
+            :name => content_for_scanner[/Registered through: (.+) \(/, 1],
  66
+            :url  => content_for_scanner[/Registered through: .*\((.+)\)\n/, 1]
  67
+          )
  68
+        end
  69
+
  70
+
  71
+        property_supported :registrant_contacts do
  72
+          contact('Registrant:', Record::Contact::TYPE_REGISTRANT)
  73
+        end
  74
+
  75
+        property_supported :admin_contacts do
  76
+          contact('Administrative Contact:', Record::Contact::TYPE_ADMIN)
  77
+        end
  78
+
  79
+        property_supported :technical_contacts do
  80
+          contact('Technical Contact:', Record::Contact::TYPE_TECHNICAL)
  81
+        end
  82
+
  83
+        property_supported :nameservers do
  84
+          content_for_scanner[/Domain servers in listed order:\n((?:\s*[^\s\n]+\n)+)\n\s*\n/, 1].split("\n").map do |line|
  85
+            Record::Nameserver.new(line.strip)
  86
+          end
  87
+        end
  88
+
  89
+
  90
+        private
  91
+
  92
+
  93
+          def contact(element, type)
  94
+            info = content_for_scanner[/#{element}\n((.+\n)+)\n/, 1].to_s.split("\n").map(&:strip)
  95
+            # NB: Lines 1 and 5 may be absent, depending on the record.
  96
+            # The parser attempts to correct for this, but may be a bit flaky
  97
+            # on non-standard data.
  98
+            # 0 GoDaddy.com, Inc., GoDaddy.com, Inc.  dns@jomax.net
  99
+            # 1 GoDaddy.com, Inc.
  100
+            # 2 14455 N Hayden Rd Suite 219
  101
+            # 3 Scottsdale, Arizona 85260
  102
+            # 4 United States
  103
+            # 5 +1.4805058800      Fax -- +1.4805058844
  104
+            phone = ""
  105
+	    fax = ""
  106
+            if info[-1].to_s =~ /Fax --/
  107
+               phone, fax = info.delete_at(-1).to_s.scan(/^(.*) Fax --(.*)$/).first
  108
+               phone = phone.strip
  109
+               fax = fax.strip
  110
+            end
  111
+            Record::Contact.new(
  112
+              :type => type,
  113
+              :name => info[0].to_s.gsub(/\s\S+@[^\.].*\.[a-z]{2,}\s?\)?$/, "").strip,
  114
+              :organization => info.length >= 5 ? info[-4] : "",
  115
+              :address => info.length >= 4 ? info[-3] : "",
  116
+              :city => info.length >= 4 ? info[-2].to_s.partition(",")[0] : "",
  117
+              :state => info.length >= 4 ? info[-2].to_s.partition(",")[2].rpartition(" ")[0].to_s.strip : "",
  118
+              :zip => info.length >= 4 ? info[-2].to_s.rpartition(" ")[2] : "",
  119
+              :country_code => info.length >= 4 ? info[-1] : "",
  120
+              :email => info[0].to_s.scan(/[^\s]\S+@[^\.].*\.[a-z]{2,}[^\s\)\n]/).first,
  121
+              :phone => phone,
  122
+              :fax => fax
  123
+            )
  124
+          end
  125
+
  126
+      end
  127
+
  128
+    end
  129
+  end
  130
+end
2  lib/whois/server/adapters/verisign.rb
@@ -49,7 +49,7 @@ def request(string)
49 49
           def extract_referral(response)
50 50
             if response =~ /Domain Name:/
51 51
               endpoint = response.scan(/Whois Server: (.+?)$/).flatten.last
52  
-              endpoint.strip!
  52
+              endpoint.strip! if endpoint != nil
53 53
               endpoint = nil  if endpoint == "not defined"
54 54
               endpoint
55 55
             end
86  spec/fixtures/responses/whois.godaddy.com/status_registered.expected
... ...
@@ -0,0 +1,86 @@
  1
+#status
  2
+  should: %s raise_error(Whois::PropertyNotSupported)
  3
+
  4
+#available?
  5
+  should: %s == false
  6
+
  7
+#registered?
  8
+  should: %s == true
  9
+
  10
+#created_on
  11
+  should: %s be_a(Time)
  12
+  should: %s == Time.parse("02-Mar-99")
  13
+
  14
+#updated_on
  15
+  should: %s be_a(Time)
  16
+  should: %s == Time.parse("21-Oct-10")
  17
+
  18
+#expires_on
  19
+  should: %s be_a(Time)
  20
+  should: %s == Time.parse("02-Mar-19")
  21
+
  22
+
  23
+#registrar
  24
+  should: %s be_a(_registrar)
  25
+  should: %s.id           == nil
  26
+  should: %s.name         == "GoDaddy.com, Inc."
  27
+  should: %s.url          == "http://www.godaddy.com"
  28
+
  29
+#registrant_contacts
  30
+  should: %s be_a(Array)
  31
+  should: %s have(1).items
  32
+  should: %s[0] be_a(_contact)
  33
+  should: %s[0].type         == Whois::Record::Contact::TYPE_REGISTRANT
  34
+  should: %s[0].name         == "GoDaddy.com, Inc."
  35
+  should: %s[0].organization == ""
  36
+  should: %s[0].address      == "14455 N Hayden Rd Suite 219"
  37
+  should: %s[0].city         == "Scottsdale"
  38
+  should: %s[0].zip          == "85260"
  39
+  should: %s[0].state        == "Arizona"
  40
+  should: %s[0].country_code == "United States"
  41
+  should: %s[0].phone        == ""
  42
+  should: %s[0].fax          == ""
  43
+  should: %s[0].email        == ""
  44
+
  45
+#admin_contacts
  46
+  should: %s be_a(Array)
  47
+  should: %s have(1).items
  48
+  should: %s[0] be_a(_contact)
  49
+  should: %s[0].type         == Whois::Record::Contact::TYPE_ADMIN
  50
+  should: %s[0].name         == "GoDaddy.com, Inc., GoDaddy.com, Inc."
  51
+  should: %s[0].organization == "GoDaddy.com, Inc."
  52
+  should: %s[0].address      == "14455 N Hayden Rd Suite 219"
  53
+  should: %s[0].city         == "Scottsdale"
  54
+  should: %s[0].zip          == "85260"
  55
+  should: %s[0].state        == "Arizona"
  56
+  should: %s[0].country_code == "United States"
  57
+  should: %s[0].phone        == "+1.4805058800"
  58
+  should: %s[0].fax          == "+1.4805058844"
  59
+  should: %s[0].email        == "dns@jomax.net"
  60
+
  61
+#technical_contacts
  62
+  should: %s be_a(Array)
  63
+  should: %s have(1).items
  64
+  should: %s[0] be_a(_contact)
  65
+  should: %s[0].type         == Whois::Record::Contact::TYPE_TECHNICAL
  66
+  should: %s[0].name         == "GoDaddy.com, Inc., GoDaddy.com, Inc."
  67
+  should: %s[0].organization == "GoDaddy.com, Inc."
  68
+  should: %s[0].address      == "14455 N Hayden Rd Suite 219"
  69
+  should: %s[0].city         == "Scottsdale"
  70
+  should: %s[0].zip          == "85260"
  71
+  should: %s[0].state        == "Arizona"
  72
+  should: %s[0].country_code == "United States"
  73
+  should: %s[0].phone        == "+1.4805058800"
  74
+  should: %s[0].fax          == "+1.4805058844"
  75
+  should: %s[0].email        == "dns@jomax.net"
  76
+
  77
+
  78
+#nameservers
  79
+  should: %s be_a(Array)
  80
+  should: %s have(3).items
  81
+  should: %s[0] be_a(_nameserver)
  82
+  should: %s[0] == _nameserver.new(:name => "CNS1.SECURESERVER.NET")
  83
+  should: %s[1] be_a(_nameserver)
  84
+  should: %s[1] == _nameserver.new(:name => "CNS2.SECURESERVER.NET")
  85
+  should: %s[2] be_a(_nameserver)
  86
+  should: %s[2] == _nameserver.new(:name => "CNS3.SECURESERVER.NET")
60  spec/fixtures/responses/whois.godaddy.com/status_registered.txt
... ...
@@ -0,0 +1,60 @@
  1
+The data contained in GoDaddy.com, Inc.'s WhoIs database,
  2
+while believed by the company to be reliable, is provided "as is"
  3
+with no guarantee or warranties regarding its accuracy.  This
  4
+information is provided for the sole purpose of assisting you
  5
+in obtaining information about domain name registration records.
  6
+Any use of this data for any other purpose is expressly forbidden without the prior written
  7
+permission of GoDaddy.com, Inc.  By submitting an inquiry,
  8
+you agree to these terms of usage and limitations of warranty.  In particular,
  9
+you agree not to use this data to allow, enable, or otherwise make possible,
  10
+dissemination or collection of this data, in part or in its entirety, for any
  11
+purpose, such as the transmission of unsolicited advertising and
  12
+and solicitations of any kind, including spam.  You further agree
  13
+not to use this data to enable high volume, automated or robotic electronic
  14
+processes designed to collect or compile this data for any purpose,
  15
+including mining this data for your own personal or commercial purposes. 
  16
+
  17
+Please note: the registrant of the domain name is specified
  18
+in the "registrant" field.  In most cases, GoDaddy.com, Inc. 
  19
+is not the registrant of domain names listed in this database.
  20
+
  21
+
  22
+Registrant:
  23
+   GoDaddy.com, Inc.
  24
+   14455 N Hayden Rd Suite 219
  25
+   Scottsdale, Arizona 85260
  26
+   United States
  27
+
  28
+   Registered through: GoDaddy.com, Inc. (http://www.godaddy.com)
  29
+   Domain Name: GODADDY.COM
  30
+      Created on: 02-Mar-99
  31
+      Expires on: 02-Mar-19
  32
+      Last Updated on: 21-Oct-10
  33
+
  34
+   Administrative Contact:
  35
+      GoDaddy.com, Inc., GoDaddy.com, Inc.  dns@jomax.net
  36
+      GoDaddy.com, Inc.
  37
+      14455 N Hayden Rd Suite 219
  38
+      Scottsdale, Arizona 85260
  39
+      United States
  40
+      +1.4805058800      Fax -- +1.4805058844
  41
+
  42
+   Technical Contact:
  43
+      GoDaddy.com, Inc., GoDaddy.com, Inc.  dns@jomax.net
  44
+      GoDaddy.com, Inc.
  45
+      14455 N Hayden Rd Suite 219
  46
+      Scottsdale, Arizona 85260
  47
+      United States
  48
+      +1.4805058800      Fax -- +1.4805058844
  49
+
  50
+   Domain servers in listed order:
  51
+      CNS1.SECURESERVER.NET
  52
+      CNS2.SECURESERVER.NET
  53
+      CNS3.SECURESERVER.NET
  54
+
  55
+
  56
+   ****************************************************
  57
+   See Business Registration Listing
  58
+   ****************************************************
  59
+   Copy and paste the link below to view additional details:
  60
+   http://who.godaddy.com/whoischeck.aspx?domain=GODADDY.COM
Commit_comment_tip

Tip: You can add notes to lines in a file. Hover to the left of a line to make a note

Something went wrong with that request. Please try again.