PageRenderTime 55ms CodeModel.GetById 21ms RepoModel.GetById 0ms app.codeStats 0ms

/lib/whois/record/parser/whois.nic.ch.rb

http://github.com/weppos/whois
Ruby | 111 lines | 55 code | 16 blank | 40 comment | 7 complexity | 633221ee095c5b1304fa58c96d5b41f4 MD5 | raw file
Possible License(s): MIT
  1. #--
  2. # Ruby Whois
  3. #
  4. # An intelligent pure Ruby WHOIS client and parser.
  5. #
  6. # Copyright (c) 2009-2013 Simone Carletti <weppos@weppos.net>
  7. #++
  8. require 'whois/record/parser/base'
  9. module Whois
  10. class Record
  11. class Parser
  12. #
  13. # = whois.nic.ch parser
  14. #
  15. # Parser for the whois.nic.ch server.
  16. #
  17. # NOTE: This parser is just a stub and provides only a few basic methods
  18. # to check for domain availability and get domain status.
  19. # Please consider to contribute implementing missing methods.
  20. # See WhoisNicIt parser for an explanation of all available methods
  21. # and examples.
  22. #
  23. class WhoisNicCh < Base
  24. property_supported :status do
  25. if available?
  26. :available
  27. else
  28. :registered
  29. end
  30. end
  31. property_supported :available? do
  32. !!(content_for_scanner =~ /We do not have an entry/)
  33. end
  34. property_supported :registered? do
  35. !available?
  36. end
  37. property_not_supported :created_on
  38. property_not_supported :updated_on
  39. property_not_supported :expires_on
  40. # Registrant is given in the following format:
  41. #
  42. # Holder of domain name:
  43. # Name
  44. # Address line 1
  45. # Address line 2
  46. # Address line n
  47. # Contractual Language: language
  48. #
  49. property_supported :registrant_contacts do
  50. if content_for_scanner =~ /Holder of domain name:\n(.+?)\n(.+?)\nContractual Language:.*\n\n/m
  51. Record::Contact.new({ :name => $1, :address => $2, :type => Whois::Record::Contact::TYPE_REGISTRANT })
  52. end
  53. end
  54. # Technical contact is given in the following format:
  55. #
  56. # Technical contact:
  57. # Name
  58. # Address line 1
  59. # Address line 2
  60. # Address line n
  61. #
  62. property_supported :technical_contacts do
  63. if content_for_scanner =~ /Technical contact:\n(.+?)\n(.+?)\n\n/m
  64. Record::Contact.new({ :name => $1, :address => $2, :type => Whois::Record::Contact::TYPE_TECHNICAL })
  65. end
  66. end
  67. property_not_supported :admin_contacts
  68. # Nameservers are listed in the following formats:
  69. #
  70. # ns1.citrin.ch
  71. # ns1.citrin.ch [193.247.72.8]
  72. #
  73. property_supported :nameservers do
  74. if content_for_scanner =~ /Name servers:\n((.+\n)+)(?:\n|\z)/
  75. list = {}
  76. order = []
  77. $1.split("\n").map do |line|
  78. if line =~ /(.+)\t\[(.+)\]/
  79. name, ip = $1, $2
  80. order << name unless order.include?(name)
  81. list[name] ||= Record::Nameserver.new(:name => name)
  82. list[name].ipv4 = ip if Whois::Server.valid_ipv4?(ip)
  83. list[name].ipv6 = ip if Whois::Server.valid_ipv6?(ip)
  84. else
  85. order << line unless order.include?(line)
  86. list[line] ||= Record::Nameserver.new(:name => line)
  87. end
  88. end
  89. order.map { |name| list[name] }
  90. end
  91. end
  92. end
  93. end
  94. end
  95. end