What i need to do is console.log all ip adresses and objects inside services and i have no idea what to do my current code is
fetch('https://search.censys.io/api/v2/hosts/search?q=' + option1 + '&per_page=' + option2 + '&virtual_hosts=' + option3, fetchauth)
.then(response => response.json())
.then(response => console.log(response.result.hits[0].ip))
.catch(err => console.error(err));
sample API response
Im planing to display these informations inside a discord embed
You can use Array.map() to get list of IPs:
response.result.hits.map(item => item.ip)
const response = {
"code": 200,
"status": "OK",
"result": {
"query": "query",
"total": 34,
"duration": 1245,
"hits": [
{
"ip": "x.x.x.x",
"services": [
{
"port": 21,
"service_name": "FTP",
"transport_protocol": "TCP"
},
{
"port": 22,
"service_name": "SSH",
"transport_protocol": "TCP"
},
]
},
{
"ip": "y.y.y.y",
"services": [
{
"port": 80,
"service_name": "HTTP",
"transport_protocol": "TCP"
},
{
"port": 443,
"service_name": "HTTP",
"certificate": "c3ea28c3a4eaa4075c45bb3740dd4207af099727eb654b974bb0b2a5703406b2",
"transport_protocol": "TCP"
}
],
"location": {
"continent": "Europe",
"country": "France",
"country_code": "FR",
"timezone": "Europe/Paris",
"coordinates": {
"latitude": 48.8582,
"longitude": 2.3387
},
"registered_country": "France",
"registered_country_code": "FR"
},
"autonomous_system": {
"asn": 16276,
"description": "OVH",
"bgp_prefix": "51.38.0.0/16",
"name": "OVH",
"country_code": "FR"
},
"last_updated_at": "2022-07-29T12:59:03.142Z"
}
]
}
};
console.log(response.result.hits.map(a=>a.ip));