Created
October 6, 2021 06:48
-
-
Save Glamdring/544c954f452da65b5087f830ce24acab to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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