Class: Mihari::Clients::SecurityTrails

Inherits:
Base
  • Object
show all
Defined in:
lib/mihari/clients/securitytrails.rb

Overview

SecurityTrails API client

Instance Attribute Summary

Attributes inherited from Base

#base_url, #headers, #pagination_interval, #timeout

Instance Method Summary collapse

Constructor Details

#initialize(base_url = "https://api.securitytrails.com", api_key:, headers: {}, timeout: nil) ⇒ SecurityTrails

Returns a new instance of SecurityTrails.

Raises:

  • (ArgumentError)


15
16
17
18
19
20
21
# File 'lib/mihari/clients/securitytrails.rb', line 15

def initialize(base_url = "https://api.securitytrails.com", api_key:, headers: {}, timeout: nil)
  raise(ArgumentError, "api_key is required") unless api_key

  headers["apikey"] = api_key

  super(base_url, headers: headers, timeout: timeout)
end

Instance Method Details

#get_all_dns_history(domain, type:, page: 1) ⇒ Enumerable<Hash>



70
71
72
73
74
75
76
77
78
79
80
81
# File 'lib/mihari/clients/securitytrails.rb', line 70

def get_all_dns_history(domain, type:, page: 1)
  Enumerator.new do |y|
    res = get_dns_history(domain, type: type, page: page)
    y.yield res

    pages = res["pages"].to_i

    (page + 1..pages).each do |page|
      y.yield get_dns_history(domain, type: type, page: page)
    end
  end
end

#ip_search(query) ⇒ Hash

IP search



30
31
32
# File 'lib/mihari/clients/securitytrails.rb', line 30

def ip_search(query)
  search_by_ip(query)
end

#mail_search(query) ⇒ Hash

Mail search



41
42
43
# File 'lib/mihari/clients/securitytrails.rb', line 41

def mail_search(query)
  search_by_mail(query)
end

#search_by_ip(ip) ⇒ Hash



59
60
61
# File 'lib/mihari/clients/securitytrails.rb', line 59

def search_by_ip(ip)
  post_json "/v1/domains/list", json: { filter: { ipv4: ip } }
end

#search_by_mail(mail) ⇒ Hash



50
51
52
# File 'lib/mihari/clients/securitytrails.rb', line 50

def search_by_mail(mail)
  post_json "/v1/domains/list", json: { filter: { whois_email: mail } }
end