Skip to content

Instantly share code, notes, and snippets.

@fsaintjacques
Created June 23, 2015 19:42
Show Gist options
  • Save fsaintjacques/853629e18d438bbee87c to your computer and use it in GitHub Desktop.
Save fsaintjacques/853629e18d438bbee87c to your computer and use it in GitHub Desktop.
ip block manipulation
#!/usr/bin/env bash
## -*- sh-basic-offset: 2 -*-
set -o errexit -o nounset -o pipefail
ORG=$1
curl_json() {
curl -H "Accept: application/json" --silent --fail "$1"
}
find_org() {
curl_json "http://whois.arin.net/rest/nets;q=${1}?showDetails=true&showARIN=false&ext=netref2" \
| jq -c -r '.nets.net| objects, (arrays | .[])|select(.orgRef != null)|.orgRef|{"@name", "@handle"}'
}
find_org $1
#!/usr/bin/env bash
## -*- sh-basic-offset: 2 -*-
set -o errexit -o nounset -o pipefail
ORG=$1
curl_json() {
curl -H "Accept: application/json" --silent --fail "$1"
}
find_net_urls() {
curl_json "http://whois.arin.net/rest/org/${1}/nets" \
| jq -r '.nets.netRef | objects, (arrays | .[]) | select(."@handle" | startswith("NET-")) | ."$"'
}
main() {
for u in $(find_net_urls $ORG); do
curl_json $u \
| jq -r '.net.netBlocks.netBlock | objects, (arrays | .[]) | .startAddress."$" + "/" + .cidrLength."$"'
done
}
main
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment