Created
June 23, 2015 19:42
-
-
Save fsaintjacques/853629e18d438bbee87c to your computer and use it in GitHub Desktop.
ip block manipulation
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
#!/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 |
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
#!/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