[tor-commits] [compass/master] Add a column with the relay primary (IPv4) address

karsten at torproject.org karsten at torproject.org
Mon May 27 09:59:29 UTC 2013


commit e69386813093c79842efd94ddff48a882f0a6577
Author: Lunar <lunar at torproject.org>
Date:   Sun May 26 19:18:13 2013 +0200

    Add a column with the relay primary (IPv4) address
    
    Onionoo protocol specification guarantee that the first entry in or_addreses is
    always the primary IP address.
---
 compass.py            |    6 ++++--
 templates/result.html |    2 ++
 util.py               |    5 +++--
 3 files changed, 9 insertions(+), 4 deletions(-)

diff --git a/compass.py b/compass.py
index 05de2f5..c55fe98 100755
--- a/compass.py
+++ b/compass.py
@@ -259,10 +259,10 @@ class RelayStats(object):
       Print the selection returned by sort_and_reduce relays into a 
       string for the command line version.
       """
-      column_widths = [9,10,10,10,10,21,80 if options.links else 42,7,7,4,11]
+      column_widths = [9,10,10,10,10,21,80 if options.links else 42,7,7,4,16,11]
       headings = ["CW","adv_bw","P_guard","P_middle", "P_exit", "Nickname",
                   "Link" if options.links else "Fingerprint",
-                  "Exit","Guard","CC", "Autonomous System"]
+                  "Exit","Guard","CC", "IPv4", "Autonomous System"]
 
       #Print the header
       header = "".join(word.ljust(column_widths[i]) for i,word in enumerate(headings))
@@ -402,6 +402,7 @@ class RelayStats(object):
                 result.guard = '-'
             result.cc = relay.get('country', '??').upper()
             countries_in_group.add(result.cc)
+            result.primary_ip = relay.get('or_addresses', ['??:0'])[0].split(':')[0]
             result.as_no = relay.get('as_number', '??')
             result.as_name = relay.get('as_name', '??')
             result.as_info = "%s %s" %(result.as_no, result.as_name)
@@ -412,6 +413,7 @@ class RelayStats(object):
         # specially
         if options.by_country or options.by_as:
             result.nick = "*"
+            result.primary_ip = "*"
             result.fp = "(%d relays)" % relays_in_group
             result.exit = "(%d)" % exits_in_group
             result.guard = "(%d)" % guards_in_group
diff --git a/templates/result.html b/templates/result.html
index 3d4b57a..705e7a4 100644
--- a/templates/result.html
+++ b/templates/result.html
@@ -13,6 +13,7 @@
         <th>Exit</th>
         <th>Guard</th>
         <th>Country</th>
+        <th>IPv4</th>
         <th>Autonomous System</th>
       </tr>
     </thead>
@@ -35,6 +36,7 @@
         <td>{{ result.exit }}</td>
         <td>{{ result.guard }}</td>
         <td>{{ result.cc }}</td>
+        <td>{{ result.primary_ip }}</td>
         <td>{{ result.as_info }}</td>
       </tr>
       {% endfor %}
diff --git a/util.py b/util.py
index 77cb02b..fe9d7d7 100644
--- a/util.py
+++ b/util.py
@@ -57,6 +57,7 @@ class Result():
         self.exit = ""
         self.guard = ""
         self.cc = ""
+        self.primary_ip = ""
         self.as_no = ""
         self.as_name = ""
         self.as_info = ""
@@ -75,11 +76,11 @@ class Result():
       Return this Result object as a list with the fields in the order
       expected for printing.
       """
-      format_str = "%.4f%%|%.4f%%|%.4f%%|%.4f%%|%.4f%%|%s|%s|%s|%s|%s|%s"
+      format_str = "%.4f%%|%.4f%%|%.4f%%|%.4f%%|%.4f%%|%s|%s|%s|%s|%s|%s|%s"
       formatted = format_str % ( self.cw, self.adv_bw, self.p_guard, self.p_middle, self.p_exit,
                     self.nick, 
                     "https://atlas.torproject.org/#details/" + self.fp if links else self.fp,
-                    self.exit, self.guard, self.cc, self.as_info )
+                    self.exit, self.guard, self.cc, self.primary_ip, self.as_info )
       return formatted.split("|")
 
 class ResultEncoder(json.JSONEncoder):





More information about the tor-commits mailing list