Class: Ronin::IPAddress
- Includes:
- Model::Importable
- Defined in:
- lib/ronin/ip_address.rb
Overview
Represents IP addresses that can be stored in the Database.
Class Method Summary collapse
-
.extract(text, version = nil) {|ip| ... } ⇒ Object
Extracts and parses IP addresses from text.
-
.lookup(name, nameserver = nil) ⇒ Array<IPAddress>
Looks up the host name to multiple IP addresses.
-
.v4 ⇒ Array<IPAddress>
Searches for all IPv4 addresses.
-
.v6 ⇒ Array<IPAddress>
Searches for all IPv6 addresses.
-
.with_hosts(names) ⇒ Array<IPAddress>
Searches for IP addresses associated with the given host names.
-
.with_macs(macs) ⇒ Array<IPAddress>
Searches for all IP addresses associated with specific MAC addresses.
-
.with_ports(numbers) ⇒ Array<IPAddress>
Searches for IP addresses with the given open ports.
Instance Method Summary collapse
-
#last_scanned_at ⇒ Time?
Determines when the IP address was last scanned.
-
#lookup!(nameserver = nil) ⇒ Array<HostName>
Performs a reverse lookup on the IP address.
-
#recent_host_name ⇒ HostName
The host-name that was most recently used by the IP Address.
-
#recent_mac_address ⇒ MacAddress
The MAC Address that was most recently used by the IP Address.
-
#recent_os_guess ⇒ OS
The Operating System that was most recently guessed for the IP Address.
-
#to_i ⇒ Integer
Converts the address to an Integer.
-
#to_ip ⇒ IPAddr
Converts the address to an IP address object.
Methods included from Model::Importable
Methods inherited from Address
Methods included from Model
Class Method Details
.extract(text, version = nil) {|ip| ... } ⇒ Object
Extracts and parses IP addresses from text.
103 104 105 106 107 108 109 110 111 |
# File 'lib/ronin/ip_address.rb', line 103 def self.extract(text,version=nil) return enum_for(:extract,text,version).to_a unless block_given? IPAddr.extract(text,version) do |ip| yield parse(ip) end return nil end |
.lookup(name, nameserver = nil) ⇒ Array<IPAddress>
Looks up the host name to multiple IP addresses.
208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 |
# File 'lib/ronin/ip_address.rb', line 208 def self.lookup(name,nameserver=nil) host = HostName.first_or_new(:address => name) resolver = Resolv.resolver(nameserver) ips = begin resolver.getaddresses(name) rescue [] end ips.map! do |addr| IPAddress.first_or_create( :address => addr, :host_names => [host] ) end return ips end |
.v4 ⇒ Array<IPAddress>
Searches for all IPv4 addresses.
123 124 125 |
# File 'lib/ronin/ip_address.rb', line 123 def self.v4 all(:version => 4) end |
.v6 ⇒ Array<IPAddress>
Searches for all IPv6 addresses.
137 138 139 |
# File 'lib/ronin/ip_address.rb', line 137 def self.v6 all(:version => 6) end |
.with_hosts(names) ⇒ Array<IPAddress>
Searches for IP addresses associated with the given host names.
171 172 173 |
# File 'lib/ronin/ip_address.rb', line 171 def self.with_hosts(names) all('host_names.address' => names) end |
.with_macs(macs) ⇒ Array<IPAddress>
Searches for all IP addresses associated with specific MAC addresses.
154 155 156 |
# File 'lib/ronin/ip_address.rb', line 154 def self.with_macs(macs) all('mac_addresses.address' => macs) end |
.with_ports(numbers) ⇒ Array<IPAddress>
Searches for IP addresses with the given open ports.
188 189 190 |
# File 'lib/ronin/ip_address.rb', line 188 def self.with_ports(numbers) all('ports.number' => numbers) end |
Instance Method Details
#last_scanned_at ⇒ Time?
Determines when the IP address was last scanned.
316 317 318 319 320 321 322 |
# File 'lib/ronin/ip_address.rb', line 316 def last_scanned_at last_scanned_port = self.open_ports.first( :order => [:last_scanned_at.desc] ) return last_scanned_port.last_scanned_at if last_scanned_port end |
#lookup!(nameserver = nil) ⇒ Array<HostName>
Performs a reverse lookup on the IP address.
241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 |
# File 'lib/ronin/ip_address.rb', line 241 def lookup!(nameserver=nil) resolver = Resolv.resolver(nameserver) hosts = begin resolver.getnames(self.address.to_s) rescue [] end hosts.map! do |name| HostName.first_or_create( :address => name, :ip_addresses => [self] ) end return hosts end |
#recent_host_name ⇒ HostName
The host-name that was most recently used by the IP Address.
285 286 287 288 289 |
# File 'lib/ronin/ip_address.rb', line 285 def recent_host_name self.host_name_ip_addresses.all( :order => [:created_at.desc] ).host_names.first end |
#recent_mac_address ⇒ MacAddress
The MAC Address that was most recently used by the IP Address.
269 270 271 272 273 |
# File 'lib/ronin/ip_address.rb', line 269 def recent_mac_address self.ip_address_mac_addresses.all( :order => [:created_at.desc] ).mac_addresses.first end |
#recent_os_guess ⇒ OS
The Operating System that was most recently guessed for the IP Address.
302 303 304 |
# File 'lib/ronin/ip_address.rb', line 302 def recent_os_guess self.os_guesses.all(:order => [:created_at.desc]).oses.first end |
#to_i ⇒ Integer
Converts the address to an Integer.
348 349 350 |
# File 'lib/ronin/ip_address.rb', line 348 def to_i self.address.to_i end |
#to_ip ⇒ IPAddr
Converts the address to an IP address object.
334 335 336 |
# File 'lib/ronin/ip_address.rb', line 334 def to_ip self.address end |