[tor-commits] [ooni-probe/master] Merge branch 'master' into master-copy

isis at torproject.org isis at torproject.org
Fri Nov 16 00:50:07 UTC 2012


commit 7affab1647a51f639968e5742a09ce74677e579e
Merge: 4dd13f7 471312f
Author: Isis Lovecruft <isis at torproject.org>
Date:   Fri Nov 16 00:33:55 2012 +0000

    Merge branch 'master' into master-copy
    
    Apply fixes to a couple bugs in ooni.utils.net.

 ooni/utils/net.py |   94 +++++++++++++++++++++++++++++++++-------------------
 1 files changed, 60 insertions(+), 34 deletions(-)

diff --cc ooni/utils/net.py
index 2583c74,4fdff49..c5b01a3
--- a/ooni/utils/net.py
+++ b/ooni/utils/net.py
@@@ -15,38 -19,42 +19,59 @@@ from scapy.all import util
  
  from ooni.utils import log, txscapy
  
- #if sys.platformm.system() == 'Windows':
+ #if sys.platform.system() == 'Windows':
  #    import _winreg as winreg
  
- userAgents = [("Mozilla/5.0 (Windows; U; Windows NT 5.1; en-GB; rv:1.8.1.6) Gecko/20070725 Firefox/2.0.0.6", "Firefox 2.0, Windows XP"),
-               ("Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1)", "Internet Explorer 7, Windows Vista"),
-               ("Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1; .NET CLR 1.1.4322; .NET CLR 2.0.50727; .NET CLR 3.0.04506.30)", "Internet Explorer 7, Windows XP"),
-               ("Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; .NET CLR 1.1.4322)", "Internet Explorer 6, Windows XP"),
-               ("Mozilla/4.0 (compatible; MSIE 5.0; Windows NT 5.1; .NET CLR 1.1.4322)", "Internet Explorer 5, Windows XP"),
-               ("Opera/9.20 (Windows NT 6.0; U; en)", "Opera 9.2, Windows Vista"),
-               ("Opera/9.00 (Windows NT 5.1; U; en)", "Opera 9.0, Windows XP"),
-               ("Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; en) Opera 8.50", "Opera 8.5, Windows XP"),
-               ("Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; en) Opera 8.0", "Opera 8.0, Windows XP"),
-               ("Mozilla/4.0 (compatible; MSIE 6.0; MSIE 5.5; Windows NT 5.1) Opera 7.02 [en]", "Opera 7.02, Windows XP"),
-               ("Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.7.5) Gecko/20060127 Netscape/8.1", "Netscape 8.1, Windows XP")]
+ PLATFORMS = {'LINUX': sys.platform.startswith("linux"),
+              'OPENBSD': sys.platform.startswith("openbsd"),
+              'FREEBSD': sys.platform.startswith("freebsd"),
+              'NETBSD': sys.platform.startswith("netbsd"),
+              'DARWIN': sys.platform.startswith("darwin"),
+              'SOLARIS': sys.platform.startswith("sunos"),
+              'WINDOWS': sys.platform.startswith("win32")}
+ 
+ userAgents = [
+     ("Mozilla/5.0 (Windows; U; Windows NT 5.1; en-GB; rv:1.8.1.6) Gecko/20070725 Firefox/2.0.0.6", "Firefox 2.0, Windows XP"),
+     ("Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1)", "Internet Explorer 7, Windows Vista"),
+     ("Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1; .NET CLR 1.1.4322; .NET CLR 2.0.50727; .NET CLR 3.0.04506.30)", "Internet Explorer 7, Windows XP"),
+     ("Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; .NET CLR 1.1.4322)", "Internet Explorer 6, Windows XP"),
+     ("Mozilla/4.0 (compatible; MSIE 5.0; Windows NT 5.1; .NET CLR 1.1.4322)", "Internet Explorer 5, Windows XP"),
+     ("Opera/9.20 (Windows NT 6.0; U; en)", "Opera 9.2, Windows Vista"),
+     ("Opera/9.00 (Windows NT 5.1; U; en)", "Opera 9.0, Windows XP"),
+     ("Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; en) Opera 8.50", "Opera 8.5, Windows XP"),
+     ("Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; en) Opera 8.0", "Opera 8.0, Windows XP"),
+     ("Mozilla/4.0 (compatible; MSIE 6.0; MSIE 5.5; Windows NT 5.1) Opera 7.02 [en]", "Opera 7.02, Windows XP"),
+     ("Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.7.5) Gecko/20060127 Netscape/8.1", "Netscape 8.1, Windows XP")
+     ]
+ 
+ 
+ class UnsupportedPlatform(Exception):
+     """Support for this platform is not currently available."""
+ 
+ class IfaceError(Exception):
+     """Could not find default network interface."""
+ 
+ class PermissionsError(SystemExit):
+     """This test requires admin or root privileges to run. Exiting..."""
+ 
  
 +PLATFORMS = {'LINUX': sys.platform.startswith("linux"),
 +             'OPENBSD': sys.platform.startswith("openbsd"),
 +             'FREEBSD': sys.platform.startswith("freebsd"),
 +             'NETBSD': sys.platform.startswith("netbsd"),
 +             'DARWIN': sys.platform.startswith("darwin"),
 +             'SOLARIS': sys.platform.startswith("sunos"),
 +             'WINDOWS': sys.platform.startswith("win32")}
 +
 +class UnsupportedPlatform(Exception):
 +    """Support for this platform is not currently available."""
 +
 +class IfaceError(Exception):
 +    """Could not find default network interface."""
 +
 +class PermissionsError(SystemExit):
 +    """This test requires admin or root privileges to run. Exiting..."""
 +
  class StringProducer(object):
      implements(IBodyProducer)
  
@@@ -105,26 -114,29 +130,29 @@@ def getClientPlatform(platform_name=Non
              if test:
                  return name, test
  
- def getPlatformAndIfaces(platform_name=None):
 -def getPosixIface():
++def getPosixIfaces():
+     from twisted.internet.test import _posixifaces
  
-     client, test = getClientPlatform(platform_name)
+     log.msg("Attempting to discover network interfaces...")
+     ifaces = _posixifaces._interfaces()
+     ifup = tryInterfaces(ifaces)
+     return ifup
  
-     def getPosixIfaces():
-         from twisted.internet.test import _posixifaces
-         all_ifaces = _posixifaces._interfaces()
-         ifup = checkInterfaces(all_ifaces)
-         return all_ifaces
 -def getWindowsIface():
++def getWindowsIfaces():
+     from twisted.internet.test import _win32ifaces
  
-     def getWindowsIfacse():
-         from twisted.internet.test import _win32ifaces
-         all_ifaces = _win32ifaces._interfaces()
-         return all_ifaces
+     log.msg("Attempting to discover network interfaces...")
+     ifaces = _win32ifaces._interfaces()
+     ifup = tryInterfaces(ifaces)
+     return ifup
  
 -def getPlatformAndIfaces(platform_name=None):
++def getIfaces(platform_name=None):
+     client, test = getClientPlatform(platform_name)
      if client:
          if client == ('LINUX' or 'DARWIN') or client[-3:] == 'BSD':
-             all_ifaces = getPosixIfaces()
 -            return getPosixIface()
++            return getPosixIfaces()
          elif client == 'WINDOWS':
-             all_ifaces = getWindowsIfaces()
 -            return getWindowsIface()
++            return getWindowsIfaces()
          ## XXX fixme figure out how to get iface for Solaris
          else:
              return None
@@@ -146,12 -156,12 +172,12 @@@ def checkInterfaces(ifaces=None, timeou
  
      ifup = {}
      if not ifaces:
--        log.debug("net.checkInterfaces(): no interfaces specified!")
++        log.debug("checkInterfaces(): no interfaces specified!")
          return None
  
      for iface in ifaces:
          for ifname, ifaddr in iface:
--            log.debug("net.checkInterfaces(): testing iface {} by pinging"
++            log.debug("checkInterfaces(): testing iface {} by pinging"
                        + " local address {}".format(ifname, ifaddr))
              try:
                  pkt = IP(dst=ifaddr)/ICMP()
@@@ -160,7 -170,7 +186,7 @@@
                  raise PermissionsError if e.find("Errno 1") else log.err(e)
              else:
                  if ans.summary():
--                    log.debug("net.checkInterfaces(): got answer on interface %s"
++                    log.debug("checkInterfaces(): got answer on interface %s"
                               + ":\n%s".format(ifname, ans.summary()))
                      ifup.update(ifname, ifaddr)
                  else:
@@@ -174,7 -184,7 +200,7 @@@
  
  def getNonLoopbackIfaces(platform_name=None):
      try:
--        ifaces = getPlatformAndIfaces(platform_name)
++        ifaces = getIfaces(platform_name)
      except UnsupportedPlatform, up:
          log.err(up)
  
@@@ -183,8 -193,8 +209,8 @@@
          return None
      else:
          found = [{i[0]: i[2]} for i in ifaces if i[0] != 'lo']
--        log.debug("utils.net.getClientIfaces: Found non-loopback interfaces: %s"
 -                  % pprint(found))
++        log.debug("getNonLoopbackIfaces: Found non-loopback interfaces: %s"
 +                  % found)
          try:
              interfaces = checkInterfaces(found)
          except IfaceError, ie:



More information about the tor-commits mailing list