Class: Ronin::DB::ASN
- Inherits:
-
ActiveRecord::Base
- Object
- ActiveRecord::Base
- Ronin::DB::ASN
- 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?
Methods included from Model
Instance Attribute Details
#country_code ⇒ String?
The country code of the ASN.
86 |
# File 'lib/ronin/db/asn.rb', line 86 attribute :country_code, :string |
#id ⇒ Integer
The primary key of the ASN range.
36 |
# File 'lib/ronin/db/asn.rb', line 36 attribute :id, :integer |
#name ⇒ String?
The organization the ASN is currently assigned to.
92 |
# File 'lib/ronin/db/asn.rb', line 92 attribute :name, :string |
#number ⇒ Integer
The ASN number.
78 |
# File 'lib/ronin/db/asn.rb', line 78 attribute :number, :integer |
#range_end ⇒ String
The ending IP address of the ASN range.
57 |
# File 'lib/ronin/db/asn.rb', line 57 attribute :range_end, :string |
#range_end_hton ⇒ String (readonly)
The ending IP address of the ASN range, but in network byte-order.
70 |
# File 'lib/ronin/db/asn.rb', line 70 attribute :range_end_hton, :binary |
#range_start ⇒ String
The starting IP address of the ASN range.
50 |
# File 'lib/ronin/db/asn.rb', line 50 attribute :range_start, :string |
#range_start_hton ⇒ String (readonly)
The starting IP address of the ASN range, but in network byte-order.
64 |
# File 'lib/ronin/db/asn.rb', line 64 attribute :range_start_hton, :binary |
#version ⇒ Integer
Whether the ASN range represents an IPv4 or IPv6 range.
42 |
# File 'lib/ronin/db/asn.rb', line 42 attribute :version, :integer |
Class Method Details
.containing_ip(ip) ⇒ ASN?
Queries the ASN that contains the given IP address.
161 162 163 164 165 166 167 168 169 |
# File 'lib/ronin/db/asn.rb', line 161 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.
102 103 104 |
# File 'lib/ronin/db/asn.rb', line 102 def self.v4 where(version: 4) end |
.v6 ⇒ Array<ASNs>
Searches for all IPv6 ASNs.
114 115 116 |
# File 'lib/ronin/db/asn.rb', line 114 def self.v6 where(version: 6) end |
.with_country_code(country_code) ⇒ Array<ASN>
Searches for all ASNs with the matching country code.
138 139 140 |
# File 'lib/ronin/db/asn.rb', line 138 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.
150 151 152 |
# File 'lib/ronin/db/asn.rb', line 150 def self.with_name(name) where(name: name) end |
.with_number(number) ⇒ Array<ASN>
Searches for all ASNs with the matching AS number.
126 127 128 |
# File 'lib/ronin/db/asn.rb', line 126 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.
194 195 196 |
# File 'lib/ronin/db/asn.rb', line 194 def ip_addresses IPAddress.between(range_start,range_end) end |
#range_end_ipaddr ⇒ IPAddr?
183 184 185 186 187 |
# File 'lib/ronin/db/asn.rb', line 183 def range_end_ipaddr @range_end_ipaddr ||= if self.range_end IPAddr.new(self.range_end) end end |
#range_start_ipaddr ⇒ IPAddr?
174 175 176 177 178 |
# File 'lib/ronin/db/asn.rb', line 174 def range_start_ipaddr @range_start_ipaddr ||= if self.range_start IPAddr.new(self.range_start) end end |