bgp-tools 0.0.2 → 0.0.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (3) hide show
  1. checksums.yaml +4 -4
  2. data/lib/bgp_tools/as.rb +59 -0
  3. metadata +2 -1
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 2554cc545320fa21d2411e462ce68c9ef793e908
4
- data.tar.gz: 70d78b93794344c46e77c42254fe23f287db50d5
3
+ metadata.gz: 49c46ff493aff150cfd5d336c3430a2d3eb3b506
4
+ data.tar.gz: 61adf0d0028429110ed64371aaee960f91d8ce5d
5
5
  SHA512:
6
- metadata.gz: 6c9a9d28058278cd823f82a916d530366065a1d2038a3cdc971e8e6af32f391f71e3e478ff996e983c5d299e7ad0cacca53c1320f7a87b98eee8a24ba68268a6
7
- data.tar.gz: 545c9c88b052d61c49cec413a9a2168458d14f5bc4cfdf5f5e8fc85c37531a82a09e3f2d638349115935cd82fd0b6fe763c37ab6958c1ff4b2ad47660a7dbba0
6
+ metadata.gz: 52ce320de535588e8e5c20b9e7231a1c5d577ab32bdec2b049cbf3cc01c5432404195a49fcd90a71f32aa4533653dfb3feb631a0abcd4537b0ae363bc6938563
7
+ data.tar.gz: e63b46ffe13a222d83fefc57d9494c14be533bdaa02205ae734eea55afe4f857902bd020a401db48273df11a475ee26250f700f0873aba37faf083a96701d2aa
@@ -0,0 +1,59 @@
1
+ module BgpTools
2
+ class AS
3
+ attr_reader :country_of_origin, :prefix_list, :as_path_length, :ips_originated,
4
+ :bgp_peer_list
5
+ def initialize(as)
6
+ url = "http://bgp.he.net/AS#{as}"
7
+ result = RestClient.get url, user_agent: USER_AGENT
8
+ self.doc = Nokogiri::HTML(result)
9
+
10
+ set_country_of_origin
11
+ set_prefix_list
12
+ set_as_path_length
13
+ set_ips_originated
14
+ set_bgp_peer_list
15
+ end
16
+
17
+ def contains?(ip)
18
+ ipaddr = IPAddr.new(ip)
19
+ prefix_list.select {|x| x.ip_addr.include? ipaddr }.count > 0
20
+ end
21
+
22
+ private
23
+
24
+ def set_as_path_length
25
+ self.as_path_length = doc.xpath("//*[@id=\"asinfo\"]/div[2]/div[10]").first.children
26
+ .map(&:text).map(&:strip)[0].split(':')[1].strip.to_f
27
+ end
28
+
29
+ def set_bgp_peer_list
30
+ self.bgp_peer_list = doc.xpath("//*[@id=\"table_peers4\"]/tbody/tr").map do |row|
31
+ vals = row.css('td').map(&:text)
32
+ ipv6 = vals[2] == "X" ? true : false
33
+ BGPPeer.new(vals[3], vals[1], ipv6, vals[0].to_i)
34
+ end
35
+ end
36
+
37
+
38
+
39
+ def set_country_of_origin
40
+ self.country_of_origin = doc.xpath("//*[@id=\"asinfo\"]/div[2]/div[2]").map(&:text)[0].strip
41
+ end
42
+
43
+ def set_ips_originated
44
+ self.ips_originated = doc.xpath("//*[@id=\"asinfo\"]/div[2]/div[8]").first.children
45
+ .map(&:text).map(&:strip)[0].split(':')[1].strip.gsub(',', '').to_i
46
+ end
47
+
48
+ def set_prefix_list
49
+ self.prefix_list = doc.xpath("//*[@id=\"table_prefixes4\"]/tbody/tr").map do |row|
50
+ vals = row.css('td').map(&:text).map(&:strip)
51
+ ASPrefix.new(vals[1], IPAddr.new(vals[0]))
52
+ end
53
+ end
54
+
55
+ attr_writer :country_of_origin, :prefix_list, :as_path_length, :ips_originated,
56
+ :bgp_peer_list
57
+ attr_accessor :doc
58
+ end
59
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: bgp-tools
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.0.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Josh Rendek
@@ -72,6 +72,7 @@ executables: []
72
72
  extensions: []
73
73
  extra_rdoc_files: []
74
74
  files:
75
+ - lib/bgp_tools/as.rb
75
76
  - lib/bgp_tools.rb
76
77
  homepage: https://github.com/joshrendek/bgp-tools
77
78
  licenses: