Skip to content

Instantly share code, notes, and snippets.

@Glamdring
Created October 6, 2021 06:48
Show Gist options
  • Save Glamdring/544c954f452da65b5087f830ce24acab to your computer and use it in GitHub Desktop.
Save Glamdring/544c954f452da65b5087f830ce24acab to your computer and use it in GitHub Desktop.

Revisions

  1. Glamdring created this gist Oct 6, 2021.
    27 changes: 27 additions & 0 deletions FacebookBGPPrefixExtraction.java
    Original 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();
    }
    }