如何查询RIPE API获取JSON数据?如何通过RIPE REST API获取whois同款JSON数据?
Hey there! Let's tackle your two questions about working with the RIPE REST API to get JSON-formatted data, especially matching what you see from the whois command.
1. 如何查询RIPE API以获取JSON格式的数据?
The RIPE Database REST API makes it straightforward to fetch structured JSON data—you just need to specify the right request headers and parameters:
- 核心API端点: Use the search endpoint
https://rest.db.ripe.net/searchfor general queries. - 指定JSON格式: Add an
Accept: application/jsonheader to your request to tell the API you want JSON instead of the default XML. - 基本查询示例:
For example, to look up details for the IP8.8.8.8, run thiscurlcommand:curl -H "Accept: application/json" "https://rest.db.ripe.net/search?query-string=8.8.8.8&type=ip&source=ripe"query-string: The value you want to search for (IP, ASN, domain, etc.)type: Filters results to a specific object type (e.g.,ip,asn,domain,inetnum)source: Specifies the RIPE database (since RIPE handles resources for Europe, Middle East, and Central Asia)
You can adjust the query-string and type parameters to search for other resource types—like an ASN (type=asn) or domain (type=domain).
2. 如何获取与whois命令输出一致的JSON格式数据?
The whois command returns raw RIPE database objects (like inetnum for IP ranges, aut-num for ASNs). To get the exact same data in JSON, you need to target those specific objects directly:
Step 1: Find the exact object path (if you don't know it)
First, use the search API to locate the URL of the object that matches your whois result. For example, searching for 8.8.8.8 will return a link to the inetnum object for 8.8.8.0-8.8.8.255.
Step 2: Fetch the object directly
Once you have the object path, request it with the JSON accept header. Using the inetnum example:
curl -H "Accept: application/json" "https://rest.db.ripe.net/ripe/inetnum/8.8.8.0-8.8.8.255"
What makes this match the whois output?
The JSON response will include an attributes array that maps directly to the lines in the whois output. For example:
whoisline:netname: LVLT-GOGL-8-8-8- JSON equivalent:
{"name": "netname", "value": "LVLT-GOGL-8-8-8"}
All fields from the whois output (like descr, country, admin-c, tech-c) will be present in this attributes array.
Tip for bulk or unknown objects
If you're working with a query that returns multiple objects (like a domain that has multiple associated records), the search API's JSON response will include an array of objects—each one corresponds to a section in the whois output, so you can iterate through them to get all matching data.
内容的提问来源于stack exchange,提问作者Jonathan

