Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

Handle ReferralServer directive in ARIN whois queries #204

Closed
wants to merge 2 commits into from

2 participants

@linrock

ARIN referrals should be correctly handled now. I added specs and used the queries listed in #37 as fixtures.

@weppos
Owner

@linrock would you mind to kill the Ruby /definitions folder?

@weppos
Owner

FYI, I've just killed it in master.
b56b858

@linrock

Sure, I just took it out.

@weppos weppos was assigned
@weppos weppos closed this in d6a13c5
@weppos
Owner

Thanks @linrock, excellent patch! I merged it.

@weppos weppos referenced this pull request from a commit
@weppos CHANGELOG for GH-204 9b01358
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.
View
35 data/ipv4.json
@@ -145,7 +145,8 @@
"host": "whois.apnic.net"
},
"0.0.0.0/1": {
- "host": "whois.arin.net"
+ "host": "whois.arin.net",
+ "adapter": "arin"
},
"133.0.0.0/8": {
"host": "whois.nic.ad.jp"
@@ -163,7 +164,8 @@
"host": "whois.ripe.net"
},
"141.86.0.0/16": {
- "host": "whois.arin.net"
+ "host": "whois.arin.net",
+ "adapter": "arin"
},
"141.64.0.0/11": {
"host": "whois.ripe.net"
@@ -364,16 +366,19 @@
"host": "whois.lacnic.net"
},
"128.0.0.0/2": {
- "host": "whois.arin.net"
+ "host": "whois.arin.net",
+ "adapter": "arin"
},
"192.71.0.0/16": {
"host": "whois.ripe.net"
},
"192.72.253.0/24": {
- "host": "whois.arin.net"
+ "host": "whois.arin.net",
+ "adapter": "arin"
},
"192.72.254.0/24": {
- "host": "whois.arin.net"
+ "host": "whois.arin.net",
+ "adapter": "arin"
},
"192.72.0.0/16": {
"host": "whois.apnic.net"
@@ -397,7 +402,8 @@
"host": "whois.ripe.net"
},
"192.0.0.0/8": {
- "host": "whois.arin.net"
+ "host": "whois.arin.net",
+ "adapter": "arin"
},
"193.0.0.0/8": {
"host": "whois.ripe.net"
@@ -409,7 +415,8 @@
"host": "whois.afrinic.net"
},
"198.0.0.0/7": {
- "host": "whois.arin.net"
+ "host": "whois.arin.net",
+ "adapter": "arin"
},
"200.17.0.0/16": {
"host": "whois.nic.br"
@@ -505,10 +512,12 @@
"host": "rwhois.gin.ntt.net"
},
"204.0.0.0/6": {
- "host": "whois.arin.net"
+ "host": "whois.arin.net",
+ "adapter": "arin"
},
"208.0.0.0/7": {
- "host": "whois.arin.net"
+ "host": "whois.arin.net",
+ "adapter": "arin"
},
"209.94.192.0/19": {
"host": "whois.lacnic.net"
@@ -634,10 +643,12 @@
"host": "whois.ripe.net"
},
"214.0.0.0/7": {
- "host": "whois.arin.net"
+ "host": "whois.arin.net",
+ "adapter": "arin"
},
"216.0.0.0/8": {
- "host": "whois.arin.net"
+ "host": "whois.arin.net",
+ "adapter": "arin"
},
"217.0.0.0/8": {
"host": "whois.ripe.net"
@@ -720,4 +731,4 @@
"220.0.0.0/6": {
"host": "whois.apnic.net"
}
-}
+}
View
1  lib/whois/server.rb
@@ -25,6 +25,7 @@ class Server
# customized to handle WHOIS queries for a type or a group of servers.
module Adapters
autoload :Base, "whois/server/adapters/base"
+ autoload :Arin, "whois/server/adapters/arin"
autoload :Arpa, "whois/server/adapters/arpa"
autoload :Afilias, "whois/server/adapters/afilias"
autoload :Formatted, "whois/server/adapters/formatted"
View
53 lib/whois/server/adapters/arin.rb
@@ -0,0 +1,53 @@
+#--
+# Ruby Whois
+#
+# An intelligent pure Ruby WHOIS client and parser.
+#
+# Copyright (c) 2009-2012 Simone Carletti <weppos@weppos.net>
+#++
+
+
+module Whois
+ class Server
+ module Adapters
+
+ #
+ # = Arin Adapter
+ #
+ # Provides ability to query Arin WHOIS interfaces.
+ #
+ class Arin < Base
+
+ # Executes a WHOIS query to the Arin WHOIS interface,
+ # resolving any intermediate referral,
+ # and appends the response to the client buffer.
+ #
+ # @param [String] string
+ # @return [void]
+ #
+ def request(string)
+ response = query_the_socket(string, host)
+ buffer_append response, host
+
+ if options[:referral] != false && referral = extract_referral(response)
+ response = query_the_socket(string, referral[:host], referral[:port])
+ buffer_append(response, referral[:host])
+ end
+
+ end
+
+ private
+
+ def extract_referral(response)
+ return unless response[/ReferralServer:\s*r?whois:\/\/([\w\.]+):?(\d+)/]
+ {
+ :host => $1,
+ :port => $2 ? $2.to_i : nil
+ }
+ end
+
+ end
+
+ end
+ end
+end
View
52 spec/fixtures/referrals/arin_referral_missing.txt
@@ -0,0 +1,52 @@
+#
+# The following results may also be obtained via:
+# http://whois.arin.net/rest/nets;q=4.2.2.1?showDetails=true&showARIN=false&ext=netref2
+#
+
+NetRange: 4.0.0.0 - 4.255.255.255
+CIDR: 4.0.0.0/8
+OriginAS:
+NetName: LVLT-ORG-4-8
+NetHandle: NET-4-0-0-0-1
+Parent:
+NetType: Direct Allocation
+RegDate: 1992-12-01
+Updated: 2012-02-24
+Ref: http://whois.arin.net/rest/net/NET-4-0-0-0-1
+
+
+OrgName: Level 3 Communications, Inc.
+OrgId: LVLT
+Address: 1025 Eldorado Blvd.
+City: Broomfield
+StateProv: CO
+PostalCode: 80021
+Country: US
+RegDate: 1998-05-22
+Updated: 2012-01-30
+Comment: ADDRESSES WITHIN THIS BLOCK ARE NON-PORTABLE
+Ref: http://whois.arin.net/rest/org/LVLT
+
+OrgTechHandle: IPADD5-ARIN
+OrgTechName: ipaddressing
+OrgTechPhone: +1-877-453-8353
+OrgTechEmail: ipaddressing@level3.com
+OrgTechRef: http://whois.arin.net/rest/poc/IPADD5-ARIN
+
+OrgNOCHandle: NOCSU27-ARIN
+OrgNOCName: NOC Support
+OrgNOCPhone: +1-877-453-8353
+OrgNOCEmail: noc.coreip@level3.com
+OrgNOCRef: http://whois.arin.net/rest/poc/NOCSU27-ARIN
+
+OrgAbuseHandle: APL8-ARIN
+OrgAbuseName: Abuse POC LVLT
+OrgAbusePhone: +1-877-453-8353
+OrgAbuseEmail: security@level3.com
+OrgAbuseRef: http://whois.arin.net/rest/poc/APL8-ARIN
+
+#
+# ARIN WHOIS data and services are subject to the Terms of Use
+# available at: https://www.arin.net/whois_tou.html
+#
+
View
62 spec/fixtures/referrals/arin_referral_rwhois.txt
@@ -0,0 +1,62 @@
+#
+# Query terms are ambiguous. The query is assumed to be:
+# "n 69.65.39.166"
+#
+# Use "?" to get help.
+#
+
+#
+# The following results may also be obtained via:
+# http://whois.arin.net/rest/nets;q=69.65.39.166?showDetails=true&showARIN=false&ext=netref2
+#
+
+NetRange: 69.65.0.0 - 69.65.63.255
+CIDR: 69.65.0.0/18
+OriginAS:
+NetName: IPNAP
+NetHandle: NET-69-65-0-0-1
+Parent: NET-69-0-0-0-0
+NetType: Direct Allocation
+Comment: www.gigenet.com
+RegDate: 2003-07-30
+Updated: 2012-03-02
+Ref: http://whois.arin.net/rest/net/NET-69-65-0-0-1
+
+OrgName: GigeNET
+OrgId: DMPL
+Address: 545 E Algonquin Rd
+Address: Suite D
+City: Arlington Heights
+StateProv: IL
+PostalCode: 60005
+Country: US
+RegDate: 2011-03-04
+Updated: 2011-06-23
+Comment: http://www.gigenet.com
+Ref: http://whois.arin.net/rest/org/DMPL
+
+ReferralServer: rwhois://rwhois.servernap.net:4321
+
+OrgTechHandle: IPADM152-ARIN
+OrgTechName: IP Administrator
+OrgTechPhone: +1-800-561-2656
+OrgTechEmail: ip-admin@coloquest.com
+OrgTechRef: http://whois.arin.net/rest/poc/IPADM152-ARIN
+
+OrgNOCHandle: IPADM152-ARIN
+OrgNOCName: IP Administrator
+OrgNOCPhone: +1-800-561-2656
+OrgNOCEmail: ip-admin@coloquest.com
+OrgNOCRef: http://whois.arin.net/rest/poc/IPADM152-ARIN
+
+OrgAbuseHandle: ABUSE2935-ARIN
+OrgAbuseName: Abuse Department
+OrgAbusePhone: +1-800-561-2656
+OrgAbuseEmail: abuse@gigenet.com
+OrgAbuseRef: http://whois.arin.net/rest/poc/ABUSE2935-ARIN
+
+#
+# ARIN WHOIS data and services are subject to the Terms of Use
+# available at: https://www.arin.net/whois_tou.html
+#
+
View
56 spec/fixtures/referrals/arin_referral_whois.txt
@@ -0,0 +1,56 @@
+#
+# Query terms are ambiguous. The query is assumed to be:
+# "n 130.66.76.222"
+#
+# Use "?" to get help.
+#
+
+#
+# The following results may also be obtained via:
+# http://whois.arin.net/rest/nets;q=130.66.76.222?showDetails=true&showARIN=false&ext=netref2
+#
+
+NetRange: 130.66.0.0 - 130.67.255.255
+CIDR: 130.66.0.0/15
+OriginAS:
+NetName: RIPE-ERX-130-66-0-0
+NetHandle: NET-130-66-0-0-1
+Parent: NET-130-0-0-0-0
+NetType: Early Registrations, Transferred to RIPE NCC
+Comment: These addresses have been further assigned to users in
+Comment: the RIPE NCC region. Contact information can be found in
+Comment: the RIPE database at http://www.ripe.net/whois
+RegDate: 2003-11-12
+Updated: 2003-11-12
+Ref: http://whois.arin.net/rest/net/NET-130-66-0-0-1
+
+OrgName: RIPE Network Coordination Centre
+OrgId: RIPE
+Address: P.O. Box 10096
+City: Amsterdam
+StateProv:
+PostalCode: 1001EB
+Country: NL
+RegDate:
+Updated: 2011-09-24
+Ref: http://whois.arin.net/rest/org/RIPE
+
+ReferralServer: whois://whois.ripe.net:43
+
+OrgAbuseHandle: RNO29-ARIN
+OrgAbuseName: RIPE NCC Operations
+OrgAbusePhone: +31 20 535 4444
+OrgAbuseEmail: hostmaster@ripe.net
+OrgAbuseRef: http://whois.arin.net/rest/poc/RNO29-ARIN
+
+OrgTechHandle: RNO29-ARIN
+OrgTechName: RIPE NCC Operations
+OrgTechPhone: +31 20 535 4444
+OrgTechEmail: hostmaster@ripe.net
+OrgTechRef: http://whois.arin.net/rest/poc/RNO29-ARIN
+
+#
+# ARIN WHOIS data and services are subject to the Terms of Use
+# available at: https://www.arin.net/whois_tou.html
+#
+
View
72 spec/whois/server/adapters/arin_spec.rb
@@ -0,0 +1,72 @@
+require 'spec_helper'
+
+describe Whois::Server::Adapters::Arin do
+
+ let(:definition) { [:ipv4, "0.0.0.0/1", "whois.arin.net"] }
+ let(:server) { klass.new(*definition) }
+
+ describe "#lookup" do
+ context "without referral" do
+ it "returns the WHOIS record" do
+ response = "Whois Response"
+ expected = response
+ server.query_handler.expects(:call).with("0.0.0.0", "whois.arin.net", 43).returns(response)
+ record = server.lookup("0.0.0.0")
+ record.to_s.should == expected
+ record.parts.should have(1).part
+ record.parts.should == [Whois::Record::Part.new(:body => response, :host => "whois.arin.net")]
+ end
+ end
+
+ context "with referral" do
+ it "follows whois:// referrals" do
+ referral = File.read(fixture("referrals/arin_referral_whois.txt"))
+ response = "Whois Response"
+ expected = referral + "\n" + response
+ server.query_handler.expects(:call).with("0.0.0.0", "whois.arin.net", 43).returns(referral)
+ server.query_handler.expects(:call).with("0.0.0.0", "whois.ripe.net", 43).returns(response)
+
+ record = server.lookup("0.0.0.0")
+ record.to_s.should == expected
+ record.parts.should have(2).parts
+ record.parts.should == [Whois::Record::Part.new(:body => referral, :host => "whois.arin.net"),
+ Whois::Record::Part.new(:body => response, :host => "whois.ripe.net")]
+ end
+
+ it "follows rwhois:// referrals" do
+ referral = File.read(fixture("referrals/arin_referral_rwhois.txt"))
+ response = "Whois Response"
+ expected = referral + "\n" + response
+ server.query_handler.expects(:call).with("0.0.0.0", "whois.arin.net", 43).returns(referral)
+ server.query_handler.expects(:call).with("0.0.0.0", "rwhois.servernap.net", 4321).returns(response)
+
+ record = server.lookup("0.0.0.0")
+ record.to_s.should == expected
+ record.parts.should have(2).parts
+ record.parts.should == [Whois::Record::Part.new(:body => referral, :host => "whois.arin.net"),
+ Whois::Record::Part.new(:body => response, :host => "rwhois.servernap.net")]
+ end
+
+ it "ignores referral if options[:referral] is false" do
+ referral = File.read(fixture("referrals/arin_referral_whois.txt"))
+ server.options[:referral] = false
+ server.query_handler.expects(:call).with("0.0.0.0", "whois.arin.net", 43).returns(referral)
+ server.query_handler.expects(:call).with("0.0.0.0", "whois.ripe.net", 43).never
+
+ record = server.lookup("0.0.0.0")
+ record.parts.should have(1).part
+ end
+
+ it "ignores referral (gracefully) if missing" do
+ referral = File.read(fixture("referrals/arin_referral_missing.txt"))
+ server.query_handler.expects(:call).with("0.0.0.0", "whois.arin.net", 43).returns(referral)
+ server.query_handler.expects(:call).never
+
+ record = server.lookup("0.0.0.0")
+ record.parts.should have(1).part
+ end
+ end
+
+ end
+
+end
Something went wrong with that request. Please try again.