Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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