Class: Ronin::HostName
- Includes:
- Model::Importable
- Defined in:
- lib/ronin/host_name.rb
Overview
Represents host names that can be stored in the Database.
Class Method Summary collapse
-
.domain(name) ⇒ Array<HostName>
Searches for all host names sharing a common domain name.
-
.extract(text) {|host| ... } ⇒ Array<HostName>
Extracts host-names from the given text.
-
.lookup(addr, nameserver = nil) ⇒ Array<HostName>
Looks up all host names associated with an IP address.
-
.tld(name) ⇒ Array<HostName>
Searches for all host names under the Top-Level Domain (TLD).
-
.with_ips(ips) ⇒ Array<HostName>
Searches for host names associated with the given IP address(es).
-
.with_ports(numbers) ⇒ Array<HostName>
Searches for host names with the given open port(s).
Instance Method Summary collapse
-
#last_scanned_at ⇒ Time?
Determines when the host was last scanned.
-
#lookup!(nameserver = nil) ⇒ Array<IPAddress>
Looks up all IP Addresses for the host name.
-
#recent_ip_address ⇒ IpAddress
The IP Address that was most recently used by the host name.
Methods included from Model::Importable
Methods inherited from Address
Methods included from Model
Class Method Details
.domain(name) ⇒ Array<HostName>
Searches for all host names sharing a common domain name.
163 164 165 166 |
# File 'lib/ronin/host_name.rb', line 163 def self.domain(name) all(:address.like => "#{name}.%") | all(:address.like => "%.#{name}.%") end |
.extract(text) {|host| ... } ⇒ Array<HostName>
Extracts host-names from the given text.
87 88 89 90 91 92 93 94 95 96 97 |
# File 'lib/ronin/host_name.rb', line 87 def self.extract(text) return enum_for(:extract,text).to_a unless block_given? scanner = StringScanner.new(text) while scanner.skip_until(Regexp::HOST_NAME) yield parse(scanner.matched) end return nil end |
.lookup(addr, nameserver = nil) ⇒ Array<HostName>
Looks up all host names associated with an IP address.
184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 |
# File 'lib/ronin/host_name.rb', line 184 def self.lookup(addr,nameserver=nil) addr = addr.to_s ip = IPAddress.first_or_new(:address => addr) resolver = Resolv.resolver(nameserver) hosts = begin resolver.getnames(addr) rescue [] end hosts.map! do |name| HostName.first_or_create( :address => name, :ip_addresses => [ip] ) end return hosts end |
.tld(name) ⇒ Array<HostName>
Searches for all host names under the Top-Level Domain (TLD).
146 147 148 |
# File 'lib/ronin/host_name.rb', line 146 def self.tld(name) all(:address.like => "%.#{name}") end |
.with_ips(ips) ⇒ Array<HostName>
Searches for host names associated with the given IP address(es).
112 113 114 |
# File 'lib/ronin/host_name.rb', line 112 def self.with_ips(ips) all('ip_addresses.address' => ips) end |
.with_ports(numbers) ⇒ Array<HostName>
Searches for host names with the given open port(s).
129 130 131 |
# File 'lib/ronin/host_name.rb', line 129 def self.with_ports(numbers) all('ports.number' => numbers) end |
Instance Method Details
#last_scanned_at ⇒ Time?
Determines when the host was last scanned.
264 265 266 267 268 269 270 |
# File 'lib/ronin/host_name.rb', line 264 def last_scanned_at last_scanned_url = self.urls.first( :order => [:last_scanned_at.desc] ) return last_scanned_url.last_scanned_at if last_scanned_url end |
#lookup!(nameserver = nil) ⇒ Array<IPAddress>
Looks up all IP Addresses for the host name.
220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 |
# File 'lib/ronin/host_name.rb', line 220 def lookup!(nameserver=nil) resolver = Resolv.resolver(nameserver) ips = begin resolver.getaddresses(self.address) rescue [] end ips.map! do |addr| IPAddress.first_or_create( :address => addr, :host_names => [self] ) end return ips end |
#recent_ip_address ⇒ IpAddress
The IP Address that was most recently used by the host name.
248 249 250 251 252 |
# File 'lib/ronin/host_name.rb', line 248 def recent_ip_address self.host_name_ip_addresses.all( :order => [:created_at.desc] ).ip_addresses.first end |