Class: BgpTools::AS

Inherits:
Object
  • Object
show all
Defined in:
lib/bgp_tools/as.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(as) ⇒ AS

Returns a new instance of AS.



5
6
7
8
9
10
11
12
13
14
15
# File 'lib/bgp_tools/as.rb', line 5

def initialize(as)
  url = "http://bgp.he.net/AS#{as}"
  result = RestClient.get url, user_agent: USER_AGENT
  self.doc = Nokogiri::HTML(result)

  set_country_of_origin
  set_prefix_list
  set_as_path_length
  set_ips_originated
  set_bgp_peer_list
end

Instance Attribute Details

#as_path_lengthObject

Returns the value of attribute as_path_length.



3
4
5
# File 'lib/bgp_tools/as.rb', line 3

def as_path_length
  @as_path_length
end

#bgp_peer_listObject

Returns the value of attribute bgp_peer_list.



3
4
5
# File 'lib/bgp_tools/as.rb', line 3

def bgp_peer_list
  @bgp_peer_list
end

#country_of_originObject

Returns the value of attribute country_of_origin.



3
4
5
# File 'lib/bgp_tools/as.rb', line 3

def country_of_origin
  @country_of_origin
end

#ips_originatedObject

Returns the value of attribute ips_originated.



3
4
5
# File 'lib/bgp_tools/as.rb', line 3

def ips_originated
  @ips_originated
end

#prefix_listObject

Returns the value of attribute prefix_list.



3
4
5
# File 'lib/bgp_tools/as.rb', line 3

def prefix_list
  @prefix_list
end

Instance Method Details

#contains?(ip) ⇒ Boolean

Returns:

  • (Boolean)


17
18
19
20
# File 'lib/bgp_tools/as.rb', line 17

def contains?(ip)
  ipaddr = IPAddr.new(ip)
  prefix_list.select {|x| x.ip_addr.include? ipaddr }.count > 0
end