0

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

https://pastebin.com/s7k2YLG5

Im planing to display these informations inside a discord embed

1
  • Can you post a json you need pls? Commented Jul 31, 2022 at 1:31

1 Answer 1

1

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));

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.