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

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

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Mixins::AutonomousSystem

#normalize_asn

Class Method Details

.from_dynamic!(d) ⇒ Match

Parameters:

  • d (Hash)

Returns:



120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
# File 'lib/mihari/structs/shodan.rb', line 120

def 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

Instance Method Details

#asnString?

Returns:

  • (String, nil)


66
67
68
# File 'lib/mihari/structs/shodan.rb', line 66

def asn
  attributes[:asn]
end

#hostnamesArray<String>

Returns:

  • (Array<String>)


73
74
75
# File 'lib/mihari/structs/shodan.rb', line 73

def hostnames
  attributes[:hostnames]
end

#ip_strString

Returns:

  • (String)


87
88
89
# File 'lib/mihari/structs/shodan.rb', line 87

def ip_str
  attributes[:ip_str]
end

#locationLocation

Returns:



80
81
82
# File 'lib/mihari/structs/shodan.rb', line 80

def location
  attributes[:location]
end

#metadataHash

Returns:

  • (Hash)


101
102
103
# File 'lib/mihari/structs/shodan.rb', line 101

def 
  attributes[:metadata]
end

#portInteger

Returns:

  • (Integer)


94
95
96
# File 'lib/mihari/structs/shodan.rb', line 94

def port
  attributes[:port]
end

#to_asnMihari::AutonomousSystem?

Returns:



108
109
110
111
112
# File 'lib/mihari/structs/shodan.rb', line 108

def to_asn
  return nil if asn.nil?

  Mihari::AutonomousSystem.new(asn: normalize_asn(asn))
end