Skip to content

Instantly share code, notes, and snippets.

@Glamdring
Created October 6, 2021 06:48
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Glamdring/544c954f452da65b5087f830ce24acab to your computer and use it in GitHub Desktop.
Save Glamdring/544c954f452da65b5087f830ce24acab to your computer and use it in GitHub Desktop.
public static void main(String[] args) throws Exception {
String prefixes = IOUtils.toString(new URL("https://stat.ripe.net/data/announced-prefixes/data.json?resource=AS32934").openStream());
ObjectMapper mapper = new ObjectMapper();
JsonNode root = mapper.readTree(prefixes);
for (JsonNode prefixNode : root.get("data").get("prefixes")) {
try {
String prefix = prefixNode.get("prefix").asText();
// skip IPv6
if (!prefix.contains(":")) {
String updates = IOUtils.toString(new URL("https://stat.ripe.net/data/bgp-updates/data.json?resource=" + prefix).openStream());
JsonNode updateRoot = mapper.readTree(updates);
int annoucenments = 0;
int withdrawals = 0;
for (JsonNode updateNode : updateRoot.get("data").get("updates")) {
String type = updateNode.get("type").asText();
if (type.equals("A")) {
annoucenments++;
} else if (type.equals("W")) {
withdrawals++;
}
}
System.out.println(prefix + "," + annoucenments + "," + withdrawals);
}
} catch (Exception ex) {
ex.printStackTrace();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment