Class: Mihari::Structs::Shodan::Match

Inherits:
Dry::Struct
  • Object
show all
Defined in:
lib/mihari/structs/shodan.rb

Class Method Summary collapse

Class Method Details

.from_dynamic!(d) ⇒ Object



28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
# File 'lib/mihari/structs/shodan.rb', line 28

def self.from_dynamic!(d)
  d = Types::Hash[d]

  # hostnames should be an array of string but sometimes Shodan returns a string
  # e.g. "hostnames": "set(['149.28.146.131.vultr.com', 'rebs.ga'])",
  # https://github.com/ninoseki/mihari/issues/424
  # so use an empty array if hostnames is a string
  hostnames = d.fetch("hostnames")
  hostnames = [] if hostnames.is_a?(String)

  new(
    asn: d["asn"],
    hostnames: hostnames,
    location: Location.from_dynamic!(d.fetch("location")),
    domains: d.fetch("domains"),
    ip_str: d.fetch("ip_str"),
    port: d.fetch("port"),
    metadata: d
  )
end