Class: Mihari::Structs::Shodan::Response
- Inherits:
-
Dry::Struct
- Object
- Dry::Struct
- Mihari::Structs::Shodan::Response
- Defined in:
- lib/mihari/structs/shodan.rb
Instance Attribute Summary collapse
- #matches ⇒ Array<Match> readonly
- #total ⇒ Integer readonly
Class Method Summary collapse
Instance Method Summary collapse
- #artifacts ⇒ Array<Mihari::Models::Artifact>
-
#collect_hostnames_by_ip(ip) ⇒ Array<String>
Collect hostnames from matches.
-
#collect_metadata_by_ip(ip) ⇒ Array<Hash>
Collect metadata from matches.
-
#collect_ports_by_ip(ip) ⇒ Array<String>
Collect ports from matches.
Instance Attribute Details
#matches ⇒ Array<Match> (readonly)
115 |
# File 'lib/mihari/structs/shodan.rb', line 115 attribute :matches, Types.Array(Match) |
#total ⇒ Integer (readonly)
119 |
# File 'lib/mihari/structs/shodan.rb', line 119 attribute :total, Types::Int |
Class Method Details
.from_dynamic!(d) ⇒ Result
185 186 187 188 189 190 191 |
# File 'lib/mihari/structs/shodan.rb', line 185 def from_dynamic!(d) d = Types::Hash[d] new( matches: d.fetch("matches", []).map { |x| Match.from_dynamic!(x) }, total: d.fetch("total") ) end |
Instance Method Details
#artifacts ⇒ Array<Mihari::Models::Artifact>
157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 |
# File 'lib/mihari/structs/shodan.rb', line 157 def artifacts matches.map do |match| = (match.ip_str) ports = collect_ports_by_ip(match.ip_str).map do |port| Mihari::Models::Port.new(port: port) end reverse_dns_names = collect_hostnames_by_ip(match.ip_str).map do |name| Mihari::Models::ReverseDnsName.new(name: name) end Mihari::Models::Artifact.new( data: match.ip_str, metadata: , autonomous_system: match._asn, geolocation: match.location.geolocation, ports: ports, reverse_dns_names: reverse_dns_names ) end end |
#collect_hostnames_by_ip(ip) ⇒ Array<String>
Collect hostnames from matches
150 151 152 |
# File 'lib/mihari/structs/shodan.rb', line 150 def collect_hostnames_by_ip(ip) matches.select { |match| match.ip_str == ip }.map(&:hostnames).flatten.uniq end |
#collect_metadata_by_ip(ip) ⇒ Array<Hash>
Collect metadata from matches
128 129 130 |
# File 'lib/mihari/structs/shodan.rb', line 128 def (ip) matches.select { |match| match.ip_str == ip }.map(&:metadata) end |
#collect_ports_by_ip(ip) ⇒ Array<String>
Collect ports from matches
139 140 141 |
# File 'lib/mihari/structs/shodan.rb', line 139 def collect_ports_by_ip(ip) matches.select { |match| match.ip_str == ip }.map(&:port) end |