Class: Ronin::DB::ASN
- Inherits:
-
ActiveRecord::Base
- Object
- ActiveRecord::Base
- Ronin::DB::ASN
- Extended by:
- Model::HasName::ClassMethods
- Includes:
- Model
- Defined in:
- lib/ronin/db/asn.rb
Overview
Represents an ASN range.
Instance Attribute Summary collapse
-
#country_code ⇒ String?
The country code of the ASN.
-
#id ⇒ Integer
The primary key of the ASN range.
-
#name ⇒ String?
The organization the ASN is currently assigned to.
-
#number ⇒ Integer
The ASN number.
-
#range_end ⇒ String
The ending IP address of the ASN range.
-
#range_end_hton ⇒ String
readonly
The ending IP address of the ASN range, but in network byte-order.
-
#range_start ⇒ String
The starting IP address of the ASN range.
-
#range_start_hton ⇒ String
readonly
The starting IP address of the ASN range, but in network byte-order.
-
#version ⇒ Integer
Whether the ASN range represents an IPv4 or IPv6 range.
Class Method Summary collapse
-
.containing_ip(ip) ⇒ ASN?
Queries the ASN that contains the given IP address.
-
.v4 ⇒ Array<ASN>
Searches for all IPv4 ASNs.
-
.v6 ⇒ Array<ASNs>
Searches for all IPv6 ASNs.
-
.with_country_code(country_code) ⇒ Array<ASN>
Searches for all ASNs with the matching country code.
-
.with_name(name) ⇒ Array<ASN>
Searches for all ASNs with the matching name.
-
.with_number(number) ⇒ Array<ASN>
Searches for all ASNs with the matching AS number.
Instance Method Summary collapse
-
#ip_addresses ⇒ Array<IPAddress>
Queries all IP addresses within the ASN IP range.
- #range_end_ipaddr ⇒ IPAddr?
- #range_start_ipaddr ⇒ IPAddr?
-
#to_s ⇒ String
Converts the ASN to a String.
Methods included from Model::HasName::ClassMethods
Methods included from Model
Instance Attribute Details
#country_code ⇒ String?
The country code of the ASN.
88 |
# File 'lib/ronin/db/asn.rb', line 88 attribute :country_code, :string |
#id ⇒ Integer
The primary key of the ASN range.
38 |
# File 'lib/ronin/db/asn.rb', line 38 attribute :id, :integer |
#name ⇒ String?
The organization the ASN is currently assigned to.
94 |
# File 'lib/ronin/db/asn.rb', line 94 attribute :name, :string |
#number ⇒ Integer
The ASN number.
80 |
# File 'lib/ronin/db/asn.rb', line 80 attribute :number, :integer |
#range_end ⇒ String
The ending IP address of the ASN range.
59 |
# File 'lib/ronin/db/asn.rb', line 59 attribute :range_end, :string |
#range_end_hton ⇒ String (readonly)
The ending IP address of the ASN range, but in network byte-order.
72 |
# File 'lib/ronin/db/asn.rb', line 72 attribute :range_end_hton, :binary |
#range_start ⇒ String
The starting IP address of the ASN range.
52 |
# File 'lib/ronin/db/asn.rb', line 52 attribute :range_start, :string |
#range_start_hton ⇒ String (readonly)
The starting IP address of the ASN range, but in network byte-order.
66 |
# File 'lib/ronin/db/asn.rb', line 66 attribute :range_start_hton, :binary |
#version ⇒ Integer
Whether the ASN range represents an IPv4 or IPv6 range.
44 |
# File 'lib/ronin/db/asn.rb', line 44 attribute :version, :integer |
Class Method Details
.containing_ip(ip) ⇒ ASN?
Queries the ASN that contains the given IP address.
163 164 165 166 167 168 169 170 171 |
# File 'lib/ronin/db/asn.rb', line 163 def self.containing_ip(ip) ip = IPAddr.new(ip) unless ip.kind_of?(IPAddr) ip_hton = ip.hton range_start_hton = self.arel_table[:range_start_hton] range_end_hton = self.arel_table[:range_end_hton] where(range_start_hton.lteq(ip_hton).and(range_end_hton.gteq(ip_hton))).first end |
.v4 ⇒ Array<ASN>
Searches for all IPv4 ASNs.
104 105 106 |
# File 'lib/ronin/db/asn.rb', line 104 def self.v4 where(version: 4) end |
.v6 ⇒ Array<ASNs>
Searches for all IPv6 ASNs.
116 117 118 |
# File 'lib/ronin/db/asn.rb', line 116 def self.v6 where(version: 6) end |
.with_country_code(country_code) ⇒ Array<ASN>
Searches for all ASNs with the matching country code.
140 141 142 |
# File 'lib/ronin/db/asn.rb', line 140 def self.with_country_code(country_code) where(country_code: country_code) end |
.with_name(name) ⇒ Array<ASN>
Searches for all ASNs with the matching name.
152 153 154 |
# File 'lib/ronin/db/asn.rb', line 152 def self.with_name(name) where(name: name) end |
.with_number(number) ⇒ Array<ASN>
Searches for all ASNs with the matching AS number.
128 129 130 |
# File 'lib/ronin/db/asn.rb', line 128 def self.with_number(number) where(number: number) end |
Instance Method Details
#ip_addresses ⇒ Array<IPAddress>
Queries all IP addresses within the ASN IP range.
196 197 198 |
# File 'lib/ronin/db/asn.rb', line 196 def ip_addresses IPAddress.between(range_start,range_end) end |
#range_end_ipaddr ⇒ IPAddr?
185 186 187 188 189 |
# File 'lib/ronin/db/asn.rb', line 185 def range_end_ipaddr @range_end_ipaddr ||= if self.range_end IPAddr.new(self.range_end) end end |
#range_start_ipaddr ⇒ IPAddr?
176 177 178 179 180 |
# File 'lib/ronin/db/asn.rb', line 176 def range_start_ipaddr @range_start_ipaddr ||= if self.range_start IPAddr.new(self.range_start) end end |
#to_s ⇒ String
Converts the ASN to a String.
208 209 210 |
# File 'lib/ronin/db/asn.rb', line 208 def to_s "AS#{self.number}" end |