Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save pierky/3e6838ef04bcbccb8c55 to your computer and use it in GitHub Desktop.
Save pierky/3e6838ef04bcbccb8c55 to your computer and use it in GitHub Desktop.
Python script used to compare RIPE Atlas results for my blog post "A quick glance at longer than /24 IPv4 prefixes"
# Python script used to compare RIPE Atlas results for my blog post "A quick glance at longer than /24 IPv4 prefixes"
# http://blog.pierky.com/a-quick-glance-at-longer-than-24-ipv4-prefixes/
import json
import urllib2
from pprint import pprint
import ripe.atlas.sagan
RIPE_ATLAS_KEY = ""
PROPS = [ "packets_received", "packets_sent", "rtt_min", "rtt_max", "rtt_median", "rtt_average" ]
TAGS = [ "route-24", "route-25", "route-28", "noroute-24", "noroute-25", "noroute-28" ]
class JSONRequest( urllib2.Request ):
def __init__( self, URL ):
urllib2.Request.__init__( self, URL )
self.add_header( "Content-Type", "application/json" )
self.add_header( "Accept", "application/json" )
def GetMsmResults( MsmID ):
JSONResponseData = urllib2.urlopen( JSONRequest( "https://atlas.ripe.net/api/v1/measurement-latest/%d/?key=%s" % ( MsmID, RIPE_ATLAS_KEY ) ) )
LatestResults = json.load( JSONResponseData )
Results = []
for ProbeID in LatestResults:
Results.append( LatestResults[ProbeID][0] )
return Results
def Process( Results, Tag, MsmID ):
MsmResults = GetMsmResults( MsmID )
for Result in MsmResults:
RIPEAtlasSaganResult = ripe.atlas.sagan.PingResult.get( Result, on_error=ripe.atlas.sagan.PingResult.ACTION_IGNORE )
ProbeID = str( RIPEAtlasSaganResult.probe_id )
if not ( ProbeID in Results ):
Results[ProbeID] = {}
Results[ProbeID][Tag] = {}
for Prop in PROPS:
Results[ProbeID][Tag][Prop] = RIPEAtlasSaganResult[Prop]
Results = {}
Process( Results, "route-24", 1767799 )
Process( Results, "route-25", 1767800 )
Process( Results, "route-28", 1767801 )
Process( Results, "noroute-24", 1767802 )
Process( Results, "noroute-25", 1767803 )
Process( Results, "noroute-28", 1767804 )
Lines = "probe_id"
for Tag in TAGS:
for Prop in PROPS:
Lines = Lines + ","
Lines = Lines + Tag + "-" + Prop
Lines = Lines + "\n"
for ProbeID in Results.keys():
Line = ProbeID
for Tag in TAGS:
for Prop in PROPS:
Line = Line + ","
Line = Line + str( ( Results[ProbeID][Tag] if Tag in Results[ProbeID] else { Prop: "" } )[Prop] )
Lines = Lines + Line
Lines = Lines + "\n"
print( Lines )
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment