[mirrorbrain-commits] r8266 - in /trunk/mb: mb.py mb/asn.py mb/util.py

From: <poeml_at_mirrorbrain.org>
Date: Sat, 31 Mar 2012 22:58:05 -0000
Author: poeml
Date: Sun Apr  1 00:58:05 2012
New Revision: 8266

URL: http://svn.mirrorbrain.org/viewvc/mirrorbrain?rev=8266&view=rev
Log:
mb update, mb iplookup:
- make DNS resolution work with IPv4 + IPv6

Modified:
    trunk/mb/mb.py
    trunk/mb/mb/asn.py
    trunk/mb/mb/util.py

Modified: trunk/mb/mb.py
URL: http://svn.mirrorbrain.org/viewvc/mirrorbrain/trunk/mb/mb.py?rev=8266&r1=8265&r2=8266&view=diff
==============================================================================
--- trunk/mb/mb.py	(original)
+++ trunk/mb/mb.py	Sun Apr  1 00:58:05 2012
_at_@ -346,7 +346,7 @@
         elif opts.prefix:
             print r.prefix
         else:
-            print '%s (AS%s)' % (r.prefix, r.asn)
+            print '%s (AS%s) %s' % (r.prefix, r.asn, r.ip6)
         if opts.all_prefixes:
             r2 = mb.asn.asn_prefixes(self.conn, r.asn)
             print ', '.join(r2)

Modified: trunk/mb/mb/asn.py
URL: http://svn.mirrorbrain.org/viewvc/mirrorbrain/trunk/mb/mb/asn.py?rev=8266&r1=8265&r2=8266&view=diff
==============================================================================
--- trunk/mb/mb/asn.py	(original)
+++ trunk/mb/mb/asn.py	Sun Apr  1 00:58:05 2012
_at_@ -6,14 +6,25 @@
 
 
     if s[0].isdigit():
-        a = IpAddress(s)
+        a = IpAddress()
+        if ':' in s:
+            a.ip6 = s
+        else:
+            a.ip = s
 
     else:
         import sys, socket
-        # note the difference between socket.gethostbyname 
-        # and socket.gethostbyname_ex
+        ips = []
+        ip6s = []
         try:
-            host, aliases, ips = socket.gethostbyname_ex(s)
+            for res in socket.getaddrinfo(s, 0):
+                af, socktype, proto, canonname, sa = res
+                if ':' in sa[0]:
+                    if sa[0] not in ip6s:
+                        ip6s.append(sa[0])
+                else:
+                    if sa[0] not in ips:
+                        ips.append(sa[0])
         except socket.error, e:
             if e[0] == socket.EAI_NONAME:
                 raise mb.mberr.NameOrServiceNotKnown(s)
_at_@ -22,14 +33,19 @@
                 return None
 
 
-        #print host, aliases, ips
-        if len(ips) != 1:
-            print >>sys.stderr, \
-                    '>>> warning: %r resolves to multiple IP addresses: %s' \
-                    % (s, ', '.join(ips))
-            print >>sys.stderr, '>>> see http://mirrorbrain.org/archive/mirrorbrain/0042.html why this could' \
+        #print ips
+        #print ip6s
+        if len(ips) > 1 or len(ip6s) > 1:
+            print >>sys.stderr, '>>> warning: %r resolves to multiple IP addresses: ' % s,
+            if len(ips) > 1:
+                print >>sys.stderr, ', '.join(ips),
+            if len(ip6s) > 1:
+                print >>sys.stderr, ', '.join(ip6s),
+            print >>sys.stderr, '\n>>> see http://mirrorbrain.org/archive/mirrorbrain/0042.html why this could' \
                                 ' could be a problem, and what to do about it.\n'
-        a = IpAddress(ips[0])
+        a = IpAddress()
+        if ips: a.ip = ips[0]
+        if ip6s: a.ip6 = ip6s[0]
         
 
     query = """SELECT pfx, asn \

Modified: trunk/mb/mb/util.py
URL: http://svn.mirrorbrain.org/viewvc/mirrorbrain/trunk/mb/mb/util.py?rev=8266&r1=8265&r2=8266&view=diff
==============================================================================
--- trunk/mb/mb/util.py	(original)
+++ trunk/mb/mb/util.py	Sun Apr  1 00:58:05 2012
_at_@ -19,12 +19,15 @@
 
 class IpAddress:
     """represent an IP address, or rather some data associated with it"""
-    def __init__(self, ip):
-        self.ip = ip
+    def __init__(self):
+        self.ip = None
+        self.ip6 = None
         self.asn = None
         self.prefix = None
     def __str__(self):
-        return '%s (%s AS%s)' % (self.ip, self.prefix, self.asn)
+        r = '%s (%s AS%s)' % (self.ip, self.prefix, self.asn)
+        if self.ip6:
+            r += ' %s' % self.ip6
 
 
 class Sample:




_______________________________________________
mirrorbrain-commits mailing list
Archive: http://mirrorbrain.org/archive/mirrorbrain-commits/

Note: To remove yourself from this list, send a mail with the content
 	unsubscribe
to the address mirrorbrain-commits-request_at_mirrorbrain.org
Received on Sat Mar 31 2012 - 22:58:06 GMT

This archive was generated by hypermail 2.3.0 : Sat Mar 31 2012 - 23:17:02 GMT