[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]
[or-cvs] r18402: {torctl} Add getinfo address-mappings support for determining SSL IPs (torctl/trunk/python/TorCtl)
Author: mikeperry
Date: 2009-02-05 07:52:15 -0500 (Thu, 05 Feb 2009)
New Revision: 18402
Modified:
torctl/trunk/python/TorCtl/TorCtl.py
Log:
Add getinfo address-mappings support for determining SSL IPs.
Modified: torctl/trunk/python/TorCtl/TorCtl.py
===================================================================
--- torctl/trunk/python/TorCtl/TorCtl.py 2009-02-05 12:23:49 UTC (rev 18401)
+++ torctl/trunk/python/TorCtl/TorCtl.py 2009-02-05 12:52:15 UTC (rev 18402)
@@ -161,6 +161,12 @@
self.to_addr = to_addr
self.when = when
+class AddrMap:
+ def __init__(self, from_addr, to_addr, when):
+ self.from_addr = from_addr
+ self.to_addr = to_addr
+ self.when = when
+
class BWEvent:
def __init__(self, event_name, read, written):
self.event_name = event_name
@@ -646,6 +652,36 @@
TorCtl.NetworkStatus instances."""
return parse_ns_body(self.sendAndRecv("GETINFO ns/"+who+"\r\n")[0][2])
+ def get_address_mappings(self, type="all"):
+ # TODO: Also parse errors and GMTExpiry
+ body = self.sendAndRecv("GETINFO address-mappings/"+type+"\r\n")
+
+ #print "|"+body[0][1].replace("address-mappings/"+type+"=", "")+"|"
+ #print str(body[0])
+
+ if body[0][1].replace("address-mappings/"+type+"=", "") != "":
+ # one line
+ lines = [body[0][1].replace("address-mappings/"+type+"=", "")]
+ elif not body[0][2]:
+ return []
+ else:
+ lines = body[0][2].split("\n")
+ if not lines: return []
+ ret = []
+ for l in lines:
+ #print "|"+str(l)+"|"
+ if len(l) == 0: continue #Skip last line.. it's empty
+ m = re.match(r'(\S+)\s+(\S+)\s+(\"[^"]+\"|\w+)', l)
+ if not m:
+ raise ProtocolError("ADDRMAP response misformatted.")
+ fromaddr, toaddr, when = m.groups()
+ if when.upper() == "NEVER":
+ when = None
+ else:
+ when = time.strptime(when[1:-1], "%Y-%m-%d %H:%M:%S")
+ ret.append(AddrMap(fromaddr, toaddr, when))
+ return ret
+
def get_router(self, ns):
"""Fill in a Router class corresponding to a given NS class"""
desc = self.sendAndRecv("GETINFO desc/id/" + ns.idhex + "\r\n")[0][2].split("\n")