[tor-commits] [flashproxy/master] Add -4 and -6 options to flashproxy-reg-email.

dcf at torproject.org dcf at torproject.org
Mon Oct 29 07:23:09 UTC 2012


commit b9784a4644ca8661b05167b0757d2f1805c9be11
Author: David Fifield <david at bamsoftware.com>
Date:   Sun Oct 28 20:18:29 2012 -0700

    Add -4 and -6 options to flashproxy-reg-email.
    
    Otherwise the Python socket library looks up A or AAAA depending on
    system configuration. For me this is IPv6 by default, which causes
    Gmail's SMTP server to tell me my own IPv6 address, which I don't have
    configured to accept incoming connections.
---
 flashproxy-reg-email |   17 +++++++++++++++--
 1 files changed, 15 insertions(+), 2 deletions(-)

diff --git a/flashproxy-reg-email b/flashproxy-reg-email
index 9feb38a..d9a6546 100755
--- a/flashproxy-reg-email
+++ b/flashproxy-reg-email
@@ -82,6 +82,7 @@ class options(object):
     email_addr = None
     smtp_addr = None
     debug = False
+    address_family = socket.AF_UNSPEC
 
 def usage(f = sys.stdout):
     print >> f, """\
@@ -96,6 +97,8 @@ unless you have made special arrangements to connect them to a facilitator.
 
 This program requires the M2Crypto library for Python.
 
+  -4                      name lookups use only IPv4.
+  -6                      name lookups use only IPv6.
   -d, --debug             enable debugging output (Python smtplib messages).
   -e, --email=ADDRESS     send mail to ADDRESS (default "%(email_addr)s").
   -h, --help              show this help.
@@ -162,9 +165,13 @@ options.remote_addr = (DEFAULT_REMOTE_ADDRESS, DEFAULT_REMOTE_PORT)
 options.email_addr = DEFAULT_EMAIL_ADDRESS
 options.smtp_addr = (DEFAULT_SMTP_HOST, DEFAULT_SMTP_PORT)
 
-opts, args = getopt.gnu_getopt(sys.argv[1:], "de:hs:", ["debug", "email=", "help", "smtp="])
+opts, args = getopt.gnu_getopt(sys.argv[1:], "46de:hs:", ["debug", "email=", "help", "smtp="])
 for o, a in opts:
-    if o == "-d" or o == "--debug":
+    if o == "-4":
+        options.address_family = socket.AF_INET
+    elif o == "-6":
+        options.address_family = socket.AF_INET6
+    elif o == "-d" or o == "--debug":
         options.debug = True
     elif o == "-e" or o == "--email":
         options.email_addr = a
@@ -193,6 +200,12 @@ On Debian-like systems, use the command "apt-get install python-m2crypto".\
 """
     sys.exit(1)
 
+if options.address_family != socket.AF_UNSPEC:
+    getaddrinfo = socket.getaddrinfo
+    def getaddrinfo_replacement(host, port, family, *args, **kwargs):
+        return getaddrinfo(host, port, options.address_family, *args, **kwargs)
+    socket.getaddrinfo = getaddrinfo_replacement
+
 smtp = smtplib.SMTP(options.smtp_addr[0], options.smtp_addr[1], EHLO_FQDN)
 
 if options.debug:



More information about the tor-commits mailing list