Created
October 6, 2021 06:48
-
-
Save Glamdring/544c954f452da65b5087f830ce24acab to your computer and use it in GitHub Desktop.
Revisions
-
Glamdring created this gist
Oct 6, 2021 .There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,27 @@ 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(); } }