Permalink
Cannot retrieve contributors at this time
Name already in use
A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
df-scripts/list-hemembers.py
Go to fileThis commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
executable file
28 lines (18 sloc)
846 Bytes
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/python | |
import json, csv, os, sys | |
api_key = "<<insert your API key here>>" | |
# | |
# Get all of the hemembers and print name and origin_as list | |
# | |
# | |
os.system( 'curl "https://internet2-2.deepfield.net/dimension/hemembers/positions?attributes=(match:origin_as_is,match:peer_as,match:cidrs)&api_key=' + api_key + '" -o current-hemembers.json' ) | |
with open('current-hemembers.json') as data_file: | |
current_hemembers = json.load(data_file) | |
for position_id in current_hemembers: | |
data = current_hemembers[position_id] | |
origin_as = data['match']['origin_as_is'] | |
peer_as = data['match']['peer_as'] | |
cidrs = data['match']['cidrs'] | |
print "Name: {0:25} Origin AS: {1:35} Peer AS: {2:10} CIDRS: {3}".format(data['name'], " ".join(origin_as), " ".join(peer_as), " ".join(cidrs) ) | |
data_file.close() | |
os.remove('current-hemembers.json') |