whois-parser 0.0.1 → 1.0.0.pre.beta1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (282) hide show
  1. checksums.yaml +4 -4
  2. data/.yardopts +2 -0
  3. data/CHANGELOG.md +20 -0
  4. data/CONTRIBUTING.md +40 -0
  5. data/LICENSE.txt +17 -18
  6. data/README.md +6 -24
  7. data/lib/whois/parser/contact.rb +56 -0
  8. data/lib/whois/parser/errors.rb +46 -0
  9. data/lib/whois/parser/nameserver.rb +39 -0
  10. data/lib/whois/parser/registrar.rb +25 -0
  11. data/lib/whois/parser/super_struct.rb +53 -0
  12. data/lib/whois/parser/version.rb +3 -2
  13. data/lib/whois/parser.rb +407 -3
  14. data/lib/whois/parser_extensions/whois.rb +78 -0
  15. data/lib/whois/parser_extensions/whois_record.rb +222 -0
  16. data/lib/whois/parser_extensions.rb +9 -0
  17. data/lib/whois/parsers/base.rb +412 -0
  18. data/lib/whois/parsers/base_afilias.rb +139 -0
  19. data/lib/whois/parsers/base_afilias2.rb +140 -0
  20. data/lib/whois/parsers/base_cocca.rb +97 -0
  21. data/lib/whois/parsers/base_cocca2.rb +91 -0
  22. data/lib/whois/parsers/base_icann_compliant.rb +150 -0
  23. data/lib/whois/parsers/base_icb.rb +92 -0
  24. data/lib/whois/parsers/base_iisse.rb +113 -0
  25. data/lib/whois/parsers/base_nic_fr.rb +169 -0
  26. data/lib/whois/parsers/base_shared1.rb +108 -0
  27. data/lib/whois/parsers/base_shared2.rb +127 -0
  28. data/lib/whois/parsers/base_shared3.rb +127 -0
  29. data/lib/whois/parsers/base_verisign.rb +106 -0
  30. data/lib/whois/parsers/base_whoisd.rb +145 -0
  31. data/lib/whois/parsers/blank.rb +35 -0
  32. data/lib/whois/parsers/capetown-whois.registry.net.za.rb +25 -0
  33. data/lib/whois/parsers/ccwhois.ksregistry.net.rb +25 -0
  34. data/lib/whois/parsers/ccwhois.verisign-grs.com.rb +25 -0
  35. data/lib/whois/parsers/durban-whois.registry.net.za.rb +25 -0
  36. data/lib/whois/parsers/example.rb +163 -0
  37. data/lib/whois/parsers/joburg-whois.registry.net.za.rb +25 -0
  38. data/lib/whois/parsers/kero.yachay.pe.rb +86 -0
  39. data/lib/whois/parsers/org-whois.registry.net.za.rb +25 -0
  40. data/lib/whois/parsers/tvwhois.verisign-grs.com.rb +25 -0
  41. data/lib/whois/parsers/whois.1und1.info.rb +28 -0
  42. data/lib/whois/parsers/whois.35.com.rb +23 -0
  43. data/lib/whois/parsers/whois.aeda.net.ae.rb +64 -0
  44. data/lib/whois/parsers/whois.aero.rb +58 -0
  45. data/lib/whois/parsers/whois.afilias-grs.info.rb +21 -0
  46. data/lib/whois/parsers/whois.afilias.net.rb +41 -0
  47. data/lib/whois/parsers/whois.ai.rb +62 -0
  48. data/lib/whois/parsers/whois.amnic.net.rb +79 -0
  49. data/lib/whois/parsers/whois.ascio.com.rb +29 -0
  50. data/lib/whois/parsers/whois.ati.tn.rb +116 -0
  51. data/lib/whois/parsers/whois.audns.net.au.rb +118 -0
  52. data/lib/whois/parsers/whois.ax.rb +64 -0
  53. data/lib/whois/parsers/whois.biz.rb +25 -0
  54. data/lib/whois/parsers/whois.bnnic.bn.rb +75 -0
  55. data/lib/whois/parsers/whois.cat.rb +75 -0
  56. data/lib/whois/parsers/whois.cctld.by.rb +94 -0
  57. data/lib/whois/parsers/whois.cctld.uz.rb +79 -0
  58. data/lib/whois/parsers/whois.centralnic.com.rb +140 -0
  59. data/lib/whois/parsers/whois.cira.ca.rb +192 -0
  60. data/lib/whois/parsers/whois.cmc.iq.rb +25 -0
  61. data/lib/whois/parsers/whois.cnnic.cn.rb +108 -0
  62. data/lib/whois/parsers/whois.co.ca.rb +74 -0
  63. data/lib/whois/parsers/whois.co.pl.rb +82 -0
  64. data/lib/whois/parsers/whois.co.ug.rb +82 -0
  65. data/lib/whois/parsers/whois.comlaude.com.rb +113 -0
  66. data/lib/whois/parsers/whois.corporatedomains.com.rb +28 -0
  67. data/lib/whois/parsers/whois.denic.de.rb +164 -0
  68. data/lib/whois/parsers/whois.dk-hostmaster.dk.rb +88 -0
  69. data/lib/whois/parsers/whois.dns.be.rb +120 -0
  70. data/lib/whois/parsers/whois.dns.hr.rb +97 -0
  71. data/lib/whois/parsers/whois.dns.lu.rb +126 -0
  72. data/lib/whois/parsers/whois.dns.pl.rb +151 -0
  73. data/lib/whois/parsers/whois.dns.pt.rb +77 -0
  74. data/lib/whois/parsers/whois.domain-registry.nl.rb +123 -0
  75. data/lib/whois/parsers/whois.domain.kg.rb +76 -0
  76. data/lib/whois/parsers/whois.domainregistry.ie.rb +121 -0
  77. data/lib/whois/parsers/whois.domreg.lt.rb +68 -0
  78. data/lib/whois/parsers/whois.donuts.co.rb +61 -0
  79. data/lib/whois/parsers/whois.dot.cf.rb +71 -0
  80. data/lib/whois/parsers/whois.dot.tk.rb +70 -0
  81. data/lib/whois/parsers/whois.dotgov.gov.rb +61 -0
  82. data/lib/whois/parsers/whois.dotmobiregistry.net.rb +21 -0
  83. data/lib/whois/parsers/whois.dotpostregistry.net.rb +25 -0
  84. data/lib/whois/parsers/whois.dreamhost.com.rb +23 -0
  85. data/lib/whois/parsers/whois.educause.edu.rb +200 -0
  86. data/lib/whois/parsers/whois.eenet.ee.rb +72 -0
  87. data/lib/whois/parsers/whois.enom.com.rb +34 -0
  88. data/lib/whois/parsers/whois.eu.org.rb +58 -0
  89. data/lib/whois/parsers/whois.eu.rb +130 -0
  90. data/lib/whois/parsers/whois.fi.rb +117 -0
  91. data/lib/whois/parsers/whois.gandi.net.rb +30 -0
  92. data/lib/whois/parsers/whois.gg.rb +31 -0
  93. data/lib/whois/parsers/whois.godaddy.com.rb +112 -0
  94. data/lib/whois/parsers/whois.gov.za.rb +60 -0
  95. data/lib/whois/parsers/whois.hkirc.hk.rb +70 -0
  96. data/lib/whois/parsers/whois.iana.org.rb +102 -0
  97. data/lib/whois/parsers/whois.iis.nu.rb +26 -0
  98. data/lib/whois/parsers/whois.iis.se.rb +26 -0
  99. data/lib/whois/parsers/whois.in.ua.rb +75 -0
  100. data/lib/whois/parsers/whois.inregistry.net.rb +27 -0
  101. data/lib/whois/parsers/whois.isnic.is.rb +70 -0
  102. data/lib/whois/parsers/whois.isoc.org.il.rb +75 -0
  103. data/lib/whois/parsers/whois.ja.net.rb +75 -0
  104. data/lib/whois/parsers/whois.je.rb +25 -0
  105. data/lib/whois/parsers/whois.jprs.jp.rb +103 -0
  106. data/lib/whois/parsers/whois.kenic.or.ke.rb +91 -0
  107. data/lib/whois/parsers/whois.kr.rb +79 -0
  108. data/lib/whois/parsers/whois.markmonitor.com.rb +36 -0
  109. data/lib/whois/parsers/whois.monic.mo.rb +83 -0
  110. data/lib/whois/parsers/whois.museum.rb +79 -0
  111. data/lib/whois/parsers/whois.mynic.my.rb +72 -0
  112. data/lib/whois/parsers/whois.na-nic.com.na.rb +21 -0
  113. data/lib/whois/parsers/whois.nc.rb +122 -0
  114. data/lib/whois/parsers/whois.netcom.cm.rb +26 -0
  115. data/lib/whois/parsers/whois.networksolutions.com.rb +37 -0
  116. data/lib/whois/parsers/whois.nic.ac.rb +25 -0
  117. data/lib/whois/parsers/whois.nic.af.rb +25 -0
  118. data/lib/whois/parsers/whois.nic.ag.rb +21 -0
  119. data/lib/whois/parsers/whois.nic.as.rb +63 -0
  120. data/lib/whois/parsers/whois.nic.asia.rb +107 -0
  121. data/lib/whois/parsers/whois.nic.at.rb +64 -0
  122. data/lib/whois/parsers/whois.nic.bj.rb +126 -0
  123. data/lib/whois/parsers/whois.nic.bo.rb +73 -0
  124. data/lib/whois/parsers/whois.nic.cd.rb +34 -0
  125. data/lib/whois/parsers/whois.nic.ch.rb +109 -0
  126. data/lib/whois/parsers/whois.nic.ci.rb +70 -0
  127. data/lib/whois/parsers/whois.nic.cl.rb +71 -0
  128. data/lib/whois/parsers/whois.nic.co.rb +25 -0
  129. data/lib/whois/parsers/whois.nic.college.rb +25 -0
  130. data/lib/whois/parsers/whois.nic.coop.rb +70 -0
  131. data/lib/whois/parsers/whois.nic.cx.rb +25 -0
  132. data/lib/whois/parsers/whois.nic.cz.rb +42 -0
  133. data/lib/whois/parsers/whois.nic.design.rb +25 -0
  134. data/lib/whois/parsers/whois.nic.dm.rb +25 -0
  135. data/lib/whois/parsers/whois.nic.dz.rb +58 -0
  136. data/lib/whois/parsers/whois.nic.ec.rb +34 -0
  137. data/lib/whois/parsers/whois.nic.es.rb +105 -0
  138. data/lib/whois/parsers/whois.nic.fo.rb +43 -0
  139. data/lib/whois/parsers/whois.nic.fr.rb +25 -0
  140. data/lib/whois/parsers/whois.nic.gd.rb +31 -0
  141. data/lib/whois/parsers/whois.nic.gl.rb +25 -0
  142. data/lib/whois/parsers/whois.nic.gs.rb +31 -0
  143. data/lib/whois/parsers/whois.nic.hn.rb +25 -0
  144. data/lib/whois/parsers/whois.nic.ht.rb +25 -0
  145. data/lib/whois/parsers/whois.nic.hu.rb +78 -0
  146. data/lib/whois/parsers/whois.nic.im.rb +66 -0
  147. data/lib/whois/parsers/whois.nic.io.rb +48 -0
  148. data/lib/whois/parsers/whois.nic.ir.rb +66 -0
  149. data/lib/whois/parsers/whois.nic.it.rb +159 -0
  150. data/lib/whois/parsers/whois.nic.jobs.rb +25 -0
  151. data/lib/whois/parsers/whois.nic.ki.rb +25 -0
  152. data/lib/whois/parsers/whois.nic.kz.rb +67 -0
  153. data/lib/whois/parsers/whois.nic.la.rb +25 -0
  154. data/lib/whois/parsers/whois.nic.li.rb +64 -0
  155. data/lib/whois/parsers/whois.nic.lk.rb +109 -0
  156. data/lib/whois/parsers/whois.nic.lv.rb +65 -0
  157. data/lib/whois/parsers/whois.nic.ly.rb +76 -0
  158. data/lib/whois/parsers/whois.nic.md.rb +94 -0
  159. data/lib/whois/parsers/whois.nic.me.rb +85 -0
  160. data/lib/whois/parsers/whois.nic.mg.rb +31 -0
  161. data/lib/whois/parsers/whois.nic.ms.rb +25 -0
  162. data/lib/whois/parsers/whois.nic.mu.rb +25 -0
  163. data/lib/whois/parsers/whois.nic.mx.rb +79 -0
  164. data/lib/whois/parsers/whois.nic.name.rb +68 -0
  165. data/lib/whois/parsers/whois.nic.net.ng.rb +27 -0
  166. data/lib/whois/parsers/whois.nic.net.sa.rb +70 -0
  167. data/lib/whois/parsers/whois.nic.net.sb.rb +31 -0
  168. data/lib/whois/parsers/whois.nic.nf.rb +25 -0
  169. data/lib/whois/parsers/whois.nic.org.uy.rb +75 -0
  170. data/lib/whois/parsers/whois.nic.pm.rb +25 -0
  171. data/lib/whois/parsers/whois.nic.pr.rb +84 -0
  172. data/lib/whois/parsers/whois.nic.priv.at.rb +62 -0
  173. data/lib/whois/parsers/whois.nic.pw.rb +25 -0
  174. data/lib/whois/parsers/whois.nic.re.rb +25 -0
  175. data/lib/whois/parsers/whois.nic.sh.rb +25 -0
  176. data/lib/whois/parsers/whois.nic.sl.rb +76 -0
  177. data/lib/whois/parsers/whois.nic.sm.rb +76 -0
  178. data/lib/whois/parsers/whois.nic.sn.rb +113 -0
  179. data/lib/whois/parsers/whois.nic.so.rb +70 -0
  180. data/lib/whois/parsers/whois.nic.space.rb +25 -0
  181. data/lib/whois/parsers/whois.nic.st.rb +72 -0
  182. data/lib/whois/parsers/whois.nic.tc.rb +25 -0
  183. data/lib/whois/parsers/whois.nic.tech.rb +25 -0
  184. data/lib/whois/parsers/whois.nic.tel.rb +25 -0
  185. data/lib/whois/parsers/whois.nic.tl.rb +25 -0
  186. data/lib/whois/parsers/whois.nic.tm.rb +31 -0
  187. data/lib/whois/parsers/whois.nic.tr.rb +159 -0
  188. data/lib/whois/parsers/whois.nic.travel.rb +25 -0
  189. data/lib/whois/parsers/whois.nic.uk.rb +177 -0
  190. data/lib/whois/parsers/whois.nic.us.rb +25 -0
  191. data/lib/whois/parsers/whois.nic.ve.rb +87 -0
  192. data/lib/whois/parsers/whois.nic.wf.rb +25 -0
  193. data/lib/whois/parsers/whois.nic.xxx.rb +42 -0
  194. data/lib/whois/parsers/whois.nic.xyz.rb +25 -0
  195. data/lib/whois/parsers/whois.norid.no.rb +61 -0
  196. data/lib/whois/parsers/whois.pairnic.com.rb +28 -0
  197. data/lib/whois/parsers/whois.pandi.or.id.rb +25 -0
  198. data/lib/whois/parsers/whois.pir.org.rb +90 -0
  199. data/lib/whois/parsers/whois.pnina.ps.rb +31 -0
  200. data/lib/whois/parsers/whois.register.bg.rb +83 -0
  201. data/lib/whois/parsers/whois.register.com.rb +30 -0
  202. data/lib/whois/parsers/whois.register.si.rb +73 -0
  203. data/lib/whois/parsers/whois.registre.ma.rb +63 -0
  204. data/lib/whois/parsers/whois.registro.br.rb +73 -0
  205. data/lib/whois/parsers/whois.registry.gy.rb +25 -0
  206. data/lib/whois/parsers/whois.registry.hm.rb +72 -0
  207. data/lib/whois/parsers/whois.registry.net.za.rb +139 -0
  208. data/lib/whois/parsers/whois.registry.om.rb +40 -0
  209. data/lib/whois/parsers/whois.registry.qa.rb +25 -0
  210. data/lib/whois/parsers/whois.ripe.net.rb +68 -0
  211. data/lib/whois/parsers/whois.rnids.rs.rb +134 -0
  212. data/lib/whois/parsers/whois.rotld.ro.rb +65 -0
  213. data/lib/whois/parsers/whois.rrpproxy.net.rb +32 -0
  214. data/lib/whois/parsers/whois.safenames.net.rb +48 -0
  215. data/lib/whois/parsers/whois.schlund.info.rb +34 -0
  216. data/lib/whois/parsers/whois.sgnic.sg.rb +87 -0
  217. data/lib/whois/parsers/whois.sk-nic.sk.rb +101 -0
  218. data/lib/whois/parsers/whois.smallregistry.net.rb +131 -0
  219. data/lib/whois/parsers/whois.srs.net.nz.rb +159 -0
  220. data/lib/whois/parsers/whois.sx.rb +127 -0
  221. data/lib/whois/parsers/whois.tcinet.ru.rb +114 -0
  222. data/lib/whois/parsers/whois.thnic.co.th.rb +79 -0
  223. data/lib/whois/parsers/whois.tld.ee.rb +134 -0
  224. data/lib/whois/parsers/whois.tld.sy.rb +34 -0
  225. data/lib/whois/parsers/whois.tonic.to.rb +86 -0
  226. data/lib/whois/parsers/whois.tucows.com.rb +28 -0
  227. data/lib/whois/parsers/whois.twnic.net.tw.rb +72 -0
  228. data/lib/whois/parsers/whois.tznic.or.tz.rb +25 -0
  229. data/lib/whois/parsers/whois.ua.rb +240 -0
  230. data/lib/whois/parsers/whois.udag.net.rb +28 -0
  231. data/lib/whois/parsers/whois.uniregistry.net.rb +61 -0
  232. data/lib/whois/parsers/whois.usp.ac.fj.rb +72 -0
  233. data/lib/whois/parsers/whois.verisign-grs.com.rb +49 -0
  234. data/lib/whois/parsers/whois.website.ws.rb +74 -0
  235. data/lib/whois/parsers/whois.wildwestdomains.com.rb +37 -0
  236. data/lib/whois/parsers/whois.yoursrs.com.rb +125 -0
  237. data/lib/whois/parsers/whois.za.net.rb +72 -0
  238. data/lib/whois/parsers/whois.za.org.rb +72 -0
  239. data/lib/whois/parsers/whois1.nic.bi.rb +25 -0
  240. data/lib/whois/parsers/za_central_registry.rb +68 -0
  241. data/lib/whois/parsers.rb +4 -0
  242. data/lib/whois/safe_record.rb +169 -0
  243. data/lib/whois/scanners/base.rb +116 -0
  244. data/lib/whois/scanners/base_afilias.rb +51 -0
  245. data/lib/whois/scanners/base_cocca2.rb +43 -0
  246. data/lib/whois/scanners/base_icann_compliant.rb +45 -0
  247. data/lib/whois/scanners/base_iisse.rb +36 -0
  248. data/lib/whois/scanners/base_shared1.rb +31 -0
  249. data/lib/whois/scanners/base_shared2.rb +35 -0
  250. data/lib/whois/scanners/base_shared3.rb +37 -0
  251. data/lib/whois/scanners/base_whoisd.rb +44 -0
  252. data/lib/whois/scanners/iana.rb +89 -0
  253. data/lib/whois/scanners/scannable.rb +65 -0
  254. data/lib/whois/scanners/verisign.rb +100 -0
  255. data/lib/whois/scanners/whois.ati.tn.rb +32 -0
  256. data/lib/whois/scanners/whois.audns.net.au.rb +25 -0
  257. data/lib/whois/scanners/whois.cctld.by.rb +35 -0
  258. data/lib/whois/scanners/whois.centralnic.com.rb +32 -0
  259. data/lib/whois/scanners/whois.cira.ca.rb +72 -0
  260. data/lib/whois/scanners/whois.cnnic.cn.rb +42 -0
  261. data/lib/whois/scanners/whois.denic.de.rb +96 -0
  262. data/lib/whois/scanners/whois.dns.hr.rb +25 -0
  263. data/lib/whois/scanners/whois.domainregistry.ie.rb +46 -0
  264. data/lib/whois/scanners/whois.fi.rb +39 -0
  265. data/lib/whois/scanners/whois.nc.rb +32 -0
  266. data/lib/whois/scanners/whois.nic.cz.rb +22 -0
  267. data/lib/whois/scanners/whois.nic.it.rb +92 -0
  268. data/lib/whois/scanners/whois.pir.org.rb +17 -0
  269. data/lib/whois/scanners/whois.registry.net.za.rb +92 -0
  270. data/lib/whois/scanners/whois.rnids.rs.rb +52 -0
  271. data/lib/whois/scanners/whois.smallregistry.net.rb +50 -0
  272. data/lib/whois/scanners/whois.srs.net.nz.rb +23 -0
  273. data/lib/whois/scanners/whois.sx.rb +37 -0
  274. data/lib/whois/scanners/whois.tld.ee.rb +47 -0
  275. data/lib/whois/scanners/whois.tucows.com.rb +23 -0
  276. data/lib/whois/scanners/whois.yoursrs.com.rb +24 -0
  277. data/lib/whois-parser.rb +10 -0
  278. data/whois-parser.gemspec +37 -19
  279. metadata +318 -20
  280. data/.gitignore +0 -14
  281. data/Gemfile +0 -4
  282. data/Rakefile +0 -2
@@ -0,0 +1,169 @@
1
+ require_relative 'parser'
2
+
3
+ module Whois
4
+ class SafeRecord < BasicObject
5
+
6
+ # @api private
7
+ def self.define_property_method(method)
8
+ class_eval <<-RUBY, __FILE__, __LINE__ + 1
9
+ def #{method}(*args, &block)
10
+ if property_any_supported?(:#{method})
11
+ parser.#{method}(*args, &block)
12
+ end
13
+ end
14
+ RUBY
15
+ end
16
+
17
+ # @api private
18
+ def self.define_method_method(method)
19
+ class_eval <<-RUBY, __FILE__, __LINE__ + 1
20
+ def #{method}(*args, &block)
21
+ if parser.respond_to?(:#{method})
22
+ parser.#{method}(*args, &block)
23
+ end
24
+ end
25
+ RUBY
26
+ end
27
+
28
+ # @api private
29
+ def self.define_question_method(method)
30
+ return if method.to_s.end_with?("?")
31
+ class_eval <<-RUBY, __FILE__, __LINE__ + 1
32
+ def #{method}?
33
+ !#{method}.nil?
34
+ end
35
+ RUBY
36
+ end
37
+
38
+ Parser::PROPERTIES.each do |method|
39
+ define_property_method(method)
40
+ end
41
+
42
+ Parser::METHODS.each do |method|
43
+ define_method_method(method)
44
+ end
45
+
46
+ (Parser::PROPERTIES + Parser::METHODS).each do |method|
47
+ define_question_method(method)
48
+ end
49
+
50
+
51
+ attr_reader :record
52
+
53
+ def initialize(record)
54
+ @record = record
55
+ end
56
+
57
+ alias_method :target, :record
58
+
59
+
60
+ # Checks if this class respond to given method.
61
+ #
62
+ # Overrides the default implementation to add support
63
+ # for {Whois::Parser::PROPERTIES} and {Whois::Parser::METHODS}.
64
+ #
65
+ # @return [Boolean]
66
+ #
67
+ def respond_to?(*args)
68
+ respond_to_parser_method?(args.first) || target.respond_to?(*args)
69
+ end
70
+
71
+
72
+ # Lazy-loads and returns the parser proxy for current record.
73
+ #
74
+ # @return [Whois::Parser]
75
+ def parser
76
+ @parser ||= Parser.new(record)
77
+ end
78
+
79
+ # Returns a Hash containing all supported properties for this record
80
+ # along with corresponding values.
81
+ #
82
+ # @return [{ Symbol => Object }]
83
+ def properties
84
+ hash = {}
85
+ Parser::PROPERTIES.each do |property|
86
+ hash[property] = __send__(property)
87
+ end
88
+ hash
89
+ end
90
+
91
+ # Shortcut for <tt>#registrant_contacts.first</tt>.
92
+ #
93
+ # @see Whois::Parser#registrant_contacts
94
+ #
95
+ # @return [Whois::Parser::Contact]
96
+ # If the property is supported and a contact exists.
97
+ # @return [nil]
98
+ # If the property is not supported or the contact doesn't exist.
99
+ def registrant_contact
100
+ if property_any_supported?(:registrant_contacts)
101
+ registrant_contacts.first
102
+ end
103
+ end
104
+
105
+ # Shortcut for <tt>#admin_contacts.first</tt>.
106
+ #
107
+ # @see Whois::Parser#admin_contacts
108
+ #
109
+ # @return [Whois::Parser::Contact]
110
+ # If the property is supported and a contact exists.
111
+ # @return [nil]
112
+ # If the property is not supported or the contact doesn't exist.
113
+ def admin_contact
114
+ if property_any_supported?(:admin_contacts)
115
+ admin_contacts.first
116
+ end
117
+ end
118
+
119
+ # Shortcut for <tt>#technical_contacts.first</tt>.
120
+ #
121
+ # @see Whois::Parser#technical_contacts
122
+ #
123
+ # @return [Whois::Parser::Contact]
124
+ # If the property is supported and a contact exists.
125
+ # @return [nil]
126
+ # If the property is not supported or the contact doesn't exist.
127
+ def technical_contact
128
+ if property_any_supported?(:technical_contacts)
129
+ technical_contacts.first
130
+ end
131
+ end
132
+
133
+ # Collects and returns all the contacts.
134
+ #
135
+ # @see Whois::Parser#contacts
136
+ #
137
+ # @return [Array<Whois::Parser::Contact>]
138
+ def contacts
139
+ parser.contacts
140
+ end
141
+
142
+
143
+ private
144
+
145
+ # @api private
146
+ def respond_to_parser_method?(symbol)
147
+ name = symbol.to_s =~ /\?$/ ? symbol.to_s[0..-2] : symbol
148
+ Parser::PROPERTIES.include?(name.to_sym) || Parser::METHODS.include?(name.to_sym)
149
+ end
150
+
151
+ # Checks if the property passed as symbol
152
+ # is supported in any of the parsers.
153
+ #
154
+ # @api private
155
+ # @see Whois::Parser::Parser#property_any_supported?
156
+ #
157
+ # @param [Symbol] property The name of the property to check.
158
+ # @return [Boolean]
159
+ def property_any_supported?(property)
160
+ parser.property_any_supported?(property)
161
+ end
162
+
163
+ # Delegates any missing method to Record.
164
+ def method_missing(method, *args, &block)
165
+ target.send(method, *args, &block)
166
+ end
167
+
168
+ end
169
+ end
@@ -0,0 +1,116 @@
1
+ module Whois
2
+ module Scanners
3
+
4
+ class Base
5
+
6
+ class_attribute :tokenizers
7
+ self.tokenizers = []
8
+
9
+ def self.tokenizer(name, &block)
10
+ define_method(name, &block)
11
+ end
12
+
13
+
14
+ attr_reader :settings
15
+
16
+ def initialize(settings = nil)
17
+ @settings = settings || {}
18
+ end
19
+
20
+ def parse(content)
21
+ # The temporary store.
22
+ # Scanners may use this to store pointers, states or other flags.
23
+ @tmp = {}
24
+
25
+ # A super-simple AST store.
26
+ @ast = {}
27
+
28
+ @input = StringScanner.new(content)
29
+ tokenize until @input.eos?
30
+
31
+ @ast
32
+ end
33
+
34
+
35
+ tokenizer :skip_empty_line do
36
+ @input.skip(/^\n/)
37
+ end
38
+
39
+ tokenizer :skip_blank_line do
40
+ @input.skip(/^[\s]*\n/)
41
+ end
42
+
43
+ tokenizer :skip_newline do
44
+ @input.skip(/\n/)
45
+ end
46
+
47
+ # Scan a key/value pair and stores the result in the current target.
48
+ # target is the global @ast if no '_section' is set, else '_section' is used.
49
+ tokenizer :scan_keyvalue do
50
+ if @input.scan(/(.+?):(.*?)(\n|\z)/)
51
+ key, value = @input[1].strip, @input[2].strip
52
+ target = @tmp['_section'] ? (@ast[@tmp['_section']] ||= {}) : @ast
53
+
54
+ if target[key].nil?
55
+ target[key] = value
56
+ else
57
+ target[key] = Array.wrap(target[key])
58
+ target[key] << value
59
+ end
60
+ end
61
+ end
62
+
63
+ protected
64
+
65
+ def _scan_lines_to_array(pattern)
66
+ results = []
67
+ while @input.scan(pattern)
68
+ @input[1].strip
69
+ results << @input[1].strip
70
+ end
71
+ results
72
+ end
73
+
74
+ def _scan_lines_to_hash(pattern)
75
+ results = {}
76
+ while @input.scan(pattern)
77
+ results.merge! @input[1].strip => @input[2].strip
78
+ end
79
+ results
80
+ end
81
+
82
+ def _scan_keyvalues(pattern)
83
+ results = []
84
+ while @input.scan(/(.+?):(.*?)\n/)
85
+ key, value = @input[1].strip, @input[2].strip
86
+ if results[key].nil?
87
+ results[key] = value
88
+ else
89
+ results[key] = Array.wrap(results[key])
90
+ results[key] << value
91
+ end
92
+ end
93
+ end
94
+
95
+
96
+ private
97
+
98
+ def tokenize
99
+ tokenizers.each do |tokenizer|
100
+ return if send(tokenizer)
101
+ end
102
+ unexpected_token
103
+ end
104
+
105
+ def unexpected_token
106
+ error!("Unexpected token")
107
+ end
108
+
109
+ def error!(message)
110
+ raise ParserError, "#{message}: #{@input.peek(@input.string.length)}"
111
+ end
112
+
113
+ end
114
+
115
+ end
116
+ end
@@ -0,0 +1,51 @@
1
+ require_relative 'base'
2
+
3
+ module Whois
4
+ module Scanners
5
+
6
+ # Scanner for the Afilias-based records.
7
+ class BaseAfilias < Base
8
+
9
+ self.tokenizers += [
10
+ :skip_empty_line,
11
+ :scan_available,
12
+ :scan_reserved,
13
+ :scan_throttled,
14
+ :scan_disclaimer,
15
+ :scan_keyvalue,
16
+ ]
17
+
18
+
19
+ tokenizer :scan_available do
20
+ if @input.scan(/^NOT FOUND\n/)
21
+ @ast["status:available"] = true
22
+ end
23
+ end
24
+
25
+ tokenizer :scan_reserved do
26
+ if settings[:pattern_reserved] && @input.scan(settings[:pattern_reserved])
27
+ @ast["status:reserved"] = true
28
+ end
29
+ end
30
+
31
+ # .ORG
32
+ tokenizer :scan_throttled do
33
+ if @input.match?(/^WHOIS LIMIT EXCEEDED/)
34
+ @ast["response:throttled"] = true
35
+ @input.skip(/^.+\n/)
36
+ end
37
+ end
38
+
39
+ tokenizer :scan_disclaimer do
40
+ if settings[:pattern_disclaimer]
41
+ if @input.match?(settings[:pattern_disclaimer])
42
+ @ast["field:disclaimer"] = _scan_lines_to_array(/^(.+)\n/).join(" ")
43
+ end
44
+ elsif @input.pos == 0 && @input.match?(/^(.+\n){3,}\n/)
45
+ @ast["field:disclaimer"] = _scan_lines_to_array(/^(.+)\n/).join(" ")
46
+ end
47
+ end
48
+ end
49
+
50
+ end
51
+ end
@@ -0,0 +1,43 @@
1
+ require_relative 'base'
2
+
3
+ module Whois
4
+ module Scanners
5
+
6
+ class BaseCocca2 < Base
7
+
8
+ self.tokenizers += [
9
+ :skip_empty_line,
10
+ :scan_disclaimer,
11
+ :skip_lastupdate,
12
+ :skip_token_additionalsection,
13
+ :scan_keyvalue,
14
+ ]
15
+
16
+
17
+ DISCLAIMER_MATCHES = [
18
+ "TERMS OF USE:", # global
19
+ "Terminos de Uso:", # whois.nic.hn
20
+ "The data in the WHOIS database of Meridian", # whois.meridiantld.net
21
+ "This information is provided", # whois.gg
22
+ ]
23
+
24
+ tokenizer :scan_disclaimer do
25
+ if @input.match?(/^#{DISCLAIMER_MATCHES.join("|")}/)
26
+ @ast["field:disclaimer"] = @input.scan_until(/>>>/) ||
27
+ # special handler for whois.nic.cx exception
28
+ @input.scan_until(/\Z/)
29
+ end
30
+ end
31
+
32
+ tokenizer :skip_lastupdate do
33
+ @input.skip(/>>>(.+?)<<<\n/)
34
+ end
35
+
36
+ tokenizer :skip_token_additionalsection do
37
+ @input.skip(/Additional Section\n/)
38
+ end
39
+
40
+ end
41
+
42
+ end
43
+ end
@@ -0,0 +1,45 @@
1
+ require_relative 'base'
2
+
3
+ module Whois
4
+ module Scanners
5
+
6
+ # Scanner for the Icann Compliant-based records.
7
+ class BaseIcannCompliant < Base
8
+
9
+ self.tokenizers += [
10
+ :skip_head,
11
+ :scan_available,
12
+ :scan_throttled,
13
+ :skip_empty_line,
14
+ :skip_blank_line,
15
+ :scan_keyvalue,
16
+ :skip_end,
17
+ ]
18
+
19
+ tokenizer :scan_available do
20
+ if settings[:pattern_available] && @input.skip_until(settings[:pattern_available])
21
+ @ast['status:available'] = true
22
+ end
23
+ end
24
+
25
+ tokenizer :scan_throttled do
26
+ if settings[:pattern_throttled] && @input.skip_until(settings[:pattern_throttled])
27
+ @ast['response:throttled'] = true
28
+ end
29
+ end
30
+
31
+ tokenizer :skip_head do
32
+ if @input.skip_until(/Domain Name:/)
33
+ @input.scan(/\s?(.+)\n/)
34
+ @ast["Domain Name"] = @input[1].strip
35
+ end
36
+ end
37
+
38
+ tokenizer :skip_end do
39
+ @input.terminate
40
+ end
41
+
42
+ end
43
+
44
+ end
45
+ end
@@ -0,0 +1,36 @@
1
+ require_relative 'base'
2
+
3
+ module Whois
4
+ module Scanners
5
+
6
+ # Scanner for the IIS.se company.
7
+ class BaseIisse < Base
8
+
9
+ self.tokenizers += [
10
+ :skip_empty_line,
11
+ :scan_available,
12
+ :scan_disclaimer,
13
+ :scan_keyvalue,
14
+ ]
15
+
16
+
17
+ tokenizer :scan_available do
18
+ if @input.skip(/^(domain )?"(.+)" not found.+\n/)
19
+ @ast["status:available"] = true
20
+ end
21
+ end
22
+
23
+ tokenizer :scan_disclaimer do
24
+ if @input.match?(/# Copyright/)
25
+ lines = []
26
+ while @input.scan(/#(.*)\n\n?/)
27
+ lines << @input[1].strip unless @input[1].strip == ""
28
+ end
29
+ @ast["field:disclaimer"] = lines.join(" ")
30
+ end
31
+ end
32
+
33
+ end
34
+
35
+ end
36
+ end
@@ -0,0 +1,31 @@
1
+ require_relative 'base'
2
+
3
+ module Whois
4
+ module Scanners
5
+
6
+ class BaseShared1 < Base
7
+
8
+ self.tokenizers += [
9
+ :skip_empty_line,
10
+ :scan_available,
11
+ :scan_reserved,
12
+ :scan_keyvalue,
13
+ ]
14
+
15
+
16
+ tokenizer :scan_available do
17
+ if @input.skip(/^No Data Found\n/)
18
+ @ast["status:available"] = true
19
+ end
20
+ end
21
+
22
+ tokenizer :scan_reserved do
23
+ if settings[:pattern_reserved] && @input.scan(settings[:pattern_reserved])
24
+ @ast["status:reserved"] = true
25
+ end
26
+ end
27
+
28
+ end
29
+
30
+ end
31
+ end
@@ -0,0 +1,35 @@
1
+ require_relative 'base'
2
+
3
+ module Whois
4
+ module Scanners
5
+
6
+ class BaseShared2 < Base
7
+
8
+ self.tokenizers += [
9
+ :skip_blank_line,
10
+ :scan_available,
11
+ :scan_keyvalue,
12
+ :skip_lastupdate,
13
+ :skip_fuffa,
14
+ ]
15
+
16
+
17
+ tokenizer :scan_available do
18
+ if @input.scan(/^Not found: (.+)\n/)
19
+ @ast["Domain Name"] = @input[1]
20
+ @ast["status:available"] = true
21
+ end
22
+ end
23
+
24
+ tokenizer :skip_lastupdate do
25
+ @input.skip(/>>>(.+?)<<<\n/)
26
+ end
27
+
28
+ tokenizer :skip_fuffa do
29
+ @input.skip(/^\S(.+)\n/)
30
+ end
31
+
32
+ end
33
+
34
+ end
35
+ end
@@ -0,0 +1,37 @@
1
+ require_relative 'base'
2
+
3
+ module Whois
4
+ module Scanners
5
+
6
+ class BaseShared3 < Base
7
+
8
+ self.tokenizers += [
9
+ :scan_disclaimer,
10
+ :skip_empty_line,
11
+ :skip_comment,
12
+ :scan_available,
13
+ :scan_keyvalue,
14
+ ]
15
+
16
+
17
+ tokenizer :skip_comment do
18
+ @input.skip(/^;.*\n/)
19
+ end
20
+
21
+ tokenizer :scan_available do
22
+ if @input.skip(/^not found.+\n/)
23
+ @ast["status:available"] = true
24
+ end
25
+ end
26
+
27
+ tokenizer :scan_disclaimer do
28
+ if @input.pos == 0 && @input.match?(/^;.*/)
29
+ @ast["field:disclaimer"] = _scan_lines_to_array(/^;(.*)\n/).join(" ")
30
+ @ast["field:disclaimer"].gsub!(" ", "\n")
31
+ end
32
+ end
33
+
34
+ end
35
+
36
+ end
37
+ end
@@ -0,0 +1,44 @@
1
+ require_relative 'base'
2
+
3
+ module Whois
4
+ module Scanners
5
+
6
+ # Scanner for Whoisd-based records.
7
+ class BaseWhoisd < Base
8
+
9
+ self.tokenizers += [
10
+ :scan_available,
11
+ :skip_comment,
12
+ :scan_section,
13
+ :scan_keyvalue,
14
+ :skip_empty_line,
15
+ ]
16
+
17
+
18
+ tokenizer :scan_available do
19
+ if @input.skip(/^%ERROR:101: no entries found/)
20
+ @ast['status:available'] = true
21
+ end
22
+ end
23
+
24
+ tokenizer :scan_section do
25
+ if @input.scan(/\n(contact|nsset|keyset):\s+(.+)\n/)
26
+ @tmp["_section"] = "node:#{@input[1]}/#{@input[2].strip}"
27
+ while scan_keyvalue
28
+ end
29
+ @tmp.delete("_section")
30
+ end
31
+ end
32
+
33
+ tokenizer :todo_content do
34
+ @input.scan(/(.*)\n/)
35
+ end
36
+
37
+ tokenizer :skip_comment do
38
+ @input.skip(/^%.*\n/)
39
+ end
40
+
41
+ end
42
+
43
+ end
44
+ end
@@ -0,0 +1,89 @@
1
+ require_relative 'base'
2
+
3
+ module Whois
4
+ module Scanners
5
+
6
+ class Iana < Base
7
+
8
+ self.tokenizers += [
9
+ :skip_empty_line,
10
+ :scan_disclaimer,
11
+ :scan_section,
12
+ ]
13
+
14
+
15
+ tokenizer :scan_disclaimer do
16
+ if @input.match?(/^\%(.*?)\n/)
17
+ @ast["Disclaimer"] = _scan_lines_to_array(/\%(.*?)\n/).select { |line| line =~ /\w+/ }.join(" ")
18
+ end
19
+ end
20
+
21
+ tokenizer :scan_section do
22
+ if @input.scan(/^(.+):(.+)\n/)
23
+
24
+ # Adapt the section's name depending on the first line
25
+ section = case @input[1].strip
26
+ when 'contact'
27
+ @input[2].strip # use the contact type name as identifier
28
+ when 'created', 'changed'
29
+ 'dates'
30
+ when 'nserver'
31
+ 'nameservers'
32
+ else
33
+ @input[1].strip # Default name is the first label found
34
+ end
35
+
36
+ content = parse_section_pairs
37
+ @input.match?(/\n+/) || error("Unexpected end of section")
38
+ @ast[section] = content
39
+ end
40
+ end
41
+
42
+
43
+ private
44
+
45
+ def parse_section_pairs
46
+ # Sets by default the firsts values found in the section parsing bellow
47
+ section_name, section_value = @input[1].strip, @input[2].strip
48
+ #contents = {section_name => section_value}
49
+
50
+ contents = {}
51
+
52
+ while content = parse_section_pair
53
+ contents.merge!(content)
54
+ end
55
+
56
+ if contents.has_key? section_name
57
+ contents[section_name].insert(0, "#{section_value}\n")
58
+ else
59
+ contents[section_name] = section_value
60
+ end
61
+
62
+ if !contents.empty?
63
+ contents
64
+ else
65
+ false
66
+ end
67
+ end
68
+
69
+ def parse_section_pair
70
+ if @input.scan(/^(.+):\s*(.+)\n/)
71
+ key = @input[1].strip
72
+ values = [@input[2].strip]
73
+
74
+ while value = parse_section_pair_newlinevalue(key)
75
+ values << value
76
+ end
77
+ { key => values.join("\n") }
78
+ end
79
+ end
80
+
81
+ def parse_section_pair_newlinevalue(key)
82
+ if @input.scan(/^#{key}:\s*(.+)\n/)
83
+ @input[1].strip
84
+ end
85
+ end
86
+
87
+ end
88
+ end
89
+ end