arin-rws 0.0.1 → 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
data/Rakefile ADDED
@@ -0,0 +1,4 @@
1
+ task :console do
2
+ sh "irb -rubygems -I lib -r arin-rws.rb"
3
+ end
4
+
@@ -0,0 +1,34 @@
1
+ require 'pp'
2
+
3
+ module Arin
4
+ module RWS
5
+ class Client
6
+ @@http = Net::HTTP.start(Arin::RWS::HOST, Arin::RWS::PORT)
7
+ def initialize
8
+ end
9
+
10
+ def self.query(resource)
11
+ r = @@http.get("#{Arin::RWS::BASE_PATH}/#{resource}")
12
+ result = JSON.parse(r.body)
13
+
14
+ pp result
15
+
16
+ result
17
+ end
18
+
19
+ def find_ip(ip)
20
+ r = Client::query("ip/#{ip}.json")
21
+ Arin::RWS::Network.new(r)
22
+ end
23
+
24
+ def find_cidr(cidr)
25
+ r = Client::query("cidr/#{cidr}.json")
26
+ Arin::RWS::Network.new(r)
27
+ end
28
+
29
+ def find_asn(asn)
30
+ r = Client::query("asn/#{asn}.json")
31
+ end
32
+ end
33
+ end
34
+ end
@@ -0,0 +1,23 @@
1
+ module Arin
2
+ module RWS
3
+ class Customer
4
+ attr_accessor :name, :handle, :city, :street_address, :postal_code, :registration_date
5
+
6
+ def initialize(data)
7
+ self.name = data['customer']['name']['$']
8
+ self.handle = data['customer']['handle']['$']
9
+ self.city = data['customer']['city']['$']
10
+ self.postal_code = data['customer']['postalCode']['$']
11
+ self.registration_date = DateTime.parse(data['customer']['registrationDate']['$'])
12
+
13
+ @parent_org_handle = data['customer']['parentOrgRef']['@handle']
14
+ end
15
+
16
+ def parent_org
17
+ r = Arin::RWS::Client.query("org/#{@parent_org_handle}.json")
18
+ Arin::RWS::Org.new(r)
19
+ end
20
+
21
+ end
22
+ end
23
+ end
@@ -0,0 +1,16 @@
1
+ require 'pp'
2
+ module Arin
3
+ module RWS
4
+ class NetBlock
5
+ attr_accessor :start_address, :end_address, :cidr_length, :type, :description
6
+
7
+ def initialize(data)
8
+ self.start_address = data['startAddress']['$']
9
+ self.end_address = data['endAddress']['$']
10
+ self.cidr_length = data['cidrLength']['$']
11
+ self.type = data['type']['$']
12
+ self.description = data['description']['$']
13
+ end
14
+ end
15
+ end
16
+ end
@@ -0,0 +1,77 @@
1
+ module Arin
2
+ module RWS
3
+ class Network
4
+ attr_accessor :name, :handle, :registration_date, :start_address, :end_address, :update_date, :registration_date
5
+
6
+ def initialize(data)
7
+ self.name = data['net']['name']['$']
8
+ self.handle = data['net']['handle']['$']
9
+ self.start_address = data['net']['startAddress']['$']
10
+ self.end_address = data['net']['endAddress']['$']
11
+
12
+ self.update_date = DateTime.parse(data['net']['updateDate']['$'])
13
+
14
+ if not data['net']['registrationDate'].nil?
15
+ self.registration_date = DateTime.parse(data['net']['registrationDate']['$'])
16
+ end
17
+
18
+ @netblocks = []
19
+ if not data['net']['netBlocks'].nil?
20
+ # TODO Handle arrays
21
+ @netblocks << Arin::RWS::NetBlock.new(data['net']['netBlocks']['netBlock'])
22
+ end
23
+
24
+ #@origin_as = []
25
+ #data['net']['originASes'].each do |o|
26
+ # pp o
27
+ # @origin_as.push(o['originAS']['$'])
28
+ #end
29
+
30
+ if not data['net']['originASes'].nil?
31
+ @origin_as = data['net']['originASes']['originAS']['$']
32
+ end
33
+
34
+ if not data['net']['comment'].nil?
35
+ line = data['net']['comment']['line']
36
+
37
+ if line.instance_of? Array
38
+ @comment = ""
39
+ line.each do |l|
40
+ @comment << l['$'] << "\n"
41
+ end
42
+ else
43
+
44
+ @commend = line['$']
45
+ end
46
+ end
47
+
48
+ if not data['net']['customerRef'].nil?
49
+ @customer_handle = data['net']['customerRef']['@handle']
50
+ end
51
+
52
+ if not data['net']['orgRef'].nil?
53
+ @org_handle = data['net']['orgRef']['@handle']
54
+ end
55
+
56
+ end
57
+
58
+ def origin_as
59
+ @origin_as
60
+ end
61
+
62
+ def comment
63
+ @comment
64
+ end
65
+
66
+ def customer
67
+ r = Arin::RWS::Client.query("customer/#{@customer_handle}.json")
68
+ Arin::RWS::Customer.new(r)
69
+ end
70
+
71
+ def org
72
+ r = Arin::RWS::Client.query("org/#{@org_handle}.json")
73
+ Arin::RWS::Org.new(r)
74
+ end
75
+ end
76
+ end
77
+ end
@@ -0,0 +1,28 @@
1
+ module Arin
2
+ module RWS
3
+ class Org
4
+ attr_accessor :name, :handle, :city, :street_address, :postal_code, :registration_date
5
+
6
+ def initialize(data)
7
+ self.name = data['org']['name']['$']
8
+ self.handle = data['org']['handle']['$']
9
+ self.city = data['org']['city']['$']
10
+ self.postal_code = data['org']['postalCode']['$']
11
+ self.registration_date = DateTime.parse(data['org']['registrationDate']['$'])
12
+ end
13
+
14
+ def nets
15
+ @networks = []
16
+ r = Arin::RWS::Client.query("org/#{self.handle}/nets.json")
17
+
18
+ r['nets']['netRef'].each do |n|
19
+ j = Arin::RWS::Client.query("net/#{n['@handle']}.json")
20
+ @networks << Arin::RWS::Network.new(j)
21
+ end
22
+
23
+ @networks
24
+ end
25
+
26
+ end
27
+ end
28
+ end
data/lib/arin-rws.rb CHANGED
@@ -1,25 +1,18 @@
1
1
  require 'rubygems'
2
2
  require 'json'
3
3
  require 'net/http'
4
+ require 'date'
4
5
 
5
- class Arin
6
- def initialize
7
- @base_url = "http://whois.arin.net/rest"
8
-
9
- @http = Net::HTTP.start("whois.arin.net", 80)
10
- end
11
-
12
- def query(url)
13
- #resp = Net::HTTP.get_response(URI.parse(url))
14
- begin
15
- resp = @http.get("/rest#{url}")
16
- result = JSON.parse(resp.body)
17
- rescue
18
- end
6
+ module Arin
7
+ module RWS
8
+ HOST = "whois.arin.net"
9
+ PORT = 80
10
+ BASE_PATH = "/rest"
19
11
  end
20
-
21
- def lookup_ip(ip)
22
- url = "/ip/#{ip}.json"
23
- query(url)
24
- end
25
12
  end
13
+
14
+ require 'arin-rws/client'
15
+ require 'arin-rws/netblock'
16
+ require 'arin-rws/network'
17
+ require 'arin-rws/org'
18
+ require 'arin-rws/customer'
@@ -0,0 +1,6 @@
1
+ require 'test/unit'
2
+ require 'arin-rws'
3
+
4
+ class ArinRwsTest < Test::Unit::TestCase
5
+
6
+ end
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: arin-rws
3
3
  version: !ruby/object:Gem::Version
4
- hash: 29
4
+ hash: 27
5
5
  prerelease:
6
6
  segments:
7
7
  - 0
8
8
  - 0
9
- - 1
10
- version: 0.0.1
9
+ - 2
10
+ version: 0.0.2
11
11
  platform: ruby
12
12
  authors:
13
13
  - Matt Thompson
@@ -27,7 +27,14 @@ extensions: []
27
27
  extra_rdoc_files: []
28
28
 
29
29
  files:
30
+ - lib/arin-rws/client.rb
31
+ - lib/arin-rws/customer.rb
32
+ - lib/arin-rws/netblock.rb
33
+ - lib/arin-rws/network.rb
34
+ - lib/arin-rws/org.rb
30
35
  - lib/arin-rws.rb
36
+ - Rakefile
37
+ - test/test_arin-rws.rb
31
38
  homepage: http://rubygems.org/gems/arin-rws
32
39
  licenses: []
33
40