diff --git a/plugins/Internet/plugin.py b/plugins/Internet/plugin.py index 53ca3d056..054f4b3dd 100644 --- a/plugins/Internet/plugin.py +++ b/plugins/Internet/plugin.py @@ -1,6 +1,6 @@ ### # Copyright (c) 2003-2005, Jeremiah Fincher -# Copyright (c) 2010, James Vega +# Copyright (c) 2010-2011, James Vega # All rights reserved. # # Redistribution and use in source and binary forms, with or without @@ -55,7 +55,7 @@ class Internet(callbacks.Plugin): irc.reply(hostname) else: try: - ip = socket.gethostbyname(host) + ip = socket.getaddrinfo(host, None)[0][4][0] if ip == '64.94.110.11': # Verisign sucks! irc.reply(_('Host not found.')) else: @@ -153,12 +153,22 @@ class Internet(callbacks.Plugin): Returns the hexadecimal IP for that IP. """ - quads = ip.split('.') ret = "" - for quad in quads: - i = int(quad) - ret += '%02x' % i - irc.reply(ret.upper()) + if utils.net.isIPV4(ip): + quads = ip.split('.') + for quad in quads: + i = int(quad) + ret += '%02X' % i + else: + octets = ip.split(':') + for octet in octets: + if octet: + i = int(octet, 16) + ret += '%04X' % i + else: + missing = (8 - len(octets)) * 4 + ret += '0' * missing + irc.reply(ret) hexip = wrap(hexip, ['ip']) Internet = internationalizeDocstring(Internet) diff --git a/plugins/Seen/plugin.py b/plugins/Seen/plugin.py index 565a28c54..876521352 100644 --- a/plugins/Seen/plugin.py +++ b/plugins/Seen/plugin.py @@ -1,6 +1,6 @@ ### # Copyright (c) 2002-2004, Jeremiah Fincher -# Copyright (c) 2010, James Vega +# Copyright (c) 2010-2011, James Vega # All rights reserved. # # Redistribution and use in source and binary forms, with or without @@ -68,7 +68,7 @@ class SeenDB(plugins.ChannelUserDB): def seenWildcard(self, channel, nick): nicks = ircutils.IrcSet() - nickRe = re.compile('.*'.join(nick.split('*')), re.I) + nickRe = re.compile('^%s$' % '.*'.join(nick.split('*')), re.I) for (searchChan, searchNick) in self.keys(): #print 'chan: %s ... nick: %s' % (searchChan, searchNick) if isinstance(searchNick, int): @@ -77,11 +77,8 @@ class SeenDB(plugins.ChannelUserDB): # are keyed by nick-string continue if ircutils.strEqual(searchChan, channel): - try: - s = nickRe.match(searchNick).group() - except AttributeError: - continue - nicks.add(s) + if nickRe.search(searchNick) is not None: + nicks.add(searchNick) L = [[nick, self.seen(channel, nick)] for nick in nicks] def negativeTime(x): return -x[1][0] diff --git a/plugins/Services/plugin.py b/plugins/Services/plugin.py index b763202c5..86a429e9b 100644 --- a/plugins/Services/plugin.py +++ b/plugins/Services/plugin.py @@ -247,7 +247,7 @@ class Services(callbacks.Plugin): # You have been unbanned from (oftc) irc.sendMsg(networkGroup.channels.join(channel)) elif 'isn\'t registered' in s: - self.log.warning('Received "%s isn\'t registered" from ChanServ %', + self.log.warning('Received "%s isn\'t registered" from ChanServ %s', channel, on) elif 'this channel has been registered' in s: self.log.debug('Got "Registered channel" from ChanServ %s.', on) diff --git a/src/conf.py b/src/conf.py index 7d7b41490..f38dfba33 100644 --- a/src/conf.py +++ b/src/conf.py @@ -1,6 +1,6 @@ ### # Copyright (c) 2002-2005, Jeremiah Fincher -# Copyright (c) 2008-2009, James Vega +# Copyright (c) 2008-2009,2011, James Vega # All rights reserved. # # Redistribution and use in source and binary forms, with or without @@ -1050,7 +1050,7 @@ registerGroup(supybot.servers, 'http') class IP(registry.String): """Value must be a valid IP.""" def setValue(self, v): - if v and not (utils.net.isIP(v) or utils.net.isIPV6(v)): + if v and not utils.net.isIP(v): self.error() else: registry.String.setValue(self, v) diff --git a/src/ircutils.py b/src/ircutils.py index b2ec6bd2d..bf5841005 100644 --- a/src/ircutils.py +++ b/src/ircutils.py @@ -1,6 +1,6 @@ ### # Copyright (c) 2002-2005, Jeremiah Fincher -# Copyright (c) 2009, James Vega +# Copyright (c) 2011, James Vega # All rights reserved. # # Redistribution and use in source and binary forms, with or without @@ -187,7 +187,7 @@ def banmask(hostmask): """ assert isUserHostmask(hostmask) host = hostFromHostmask(hostmask) - if utils.net.isIP(host): + if utils.net.isIPV4(host): L = host.split('.') L[-1] = '*' return '*!*@' + '.'.join(L) @@ -458,9 +458,9 @@ def replyTo(msg): return msg.nick def dccIP(ip): - """Converts an IP string to the DCC integer form.""" - assert utils.net.isIP(ip), \ - 'argument must be a string ip in xxx.xxx.xxx.xxx format.' + """Returns an IP in the proper for DCC.""" + assert utils.net.isIPV4(ip), \ + 'argument must be a string ip in xxx.yyy.zzz.www format.' i = 0 x = 256**3 for quad in ip.split('.'): diff --git a/src/utils/net.py b/src/utils/net.py index 370f3e6fc..a12b12c9f 100644 --- a/src/utils/net.py +++ b/src/utils/net.py @@ -1,5 +1,6 @@ ### # Copyright (c) 2002-2005, Jeremiah Fincher +# Copyright (c) 2011, James Vega # All rights reserved. # # Redistribution and use in source and binary forms, with or without @@ -85,7 +86,7 @@ def getSocket(host): """ addrinfo = socket.getaddrinfo(host, None) host = addrinfo[0][4][0] - if isIP(host): + if isIPV4(host): return socket.socket(socket.AF_INET, socket.SOCK_STREAM) elif isIPV6(host): return socket.socket(socket.AF_INET6, socket.SOCK_STREAM) @@ -93,16 +94,27 @@ def getSocket(host): raise socket.error, 'Something wonky happened.' def isIP(s): - """Returns whether or not a given string is an IPV4 address. + """Returns whether or not a given string is an IP address. >>> isIP('255.255.255.255') 1 - >>> isIP('abc.abc.abc.abc') + >>> isIP('::1') + 0 + """ + return isIPV4(s) or isIPV6(s) + +def isIPV4(s): + """Returns whether or not a given string is an IPV4 address. + + >>> isIPV4('255.255.255.255') + 1 + + >>> isIPV4('abc.abc.abc.abc') 0 """ try: - return bool(socket.inet_aton(s)) + return bool(socket.inet_pton(socket.AF_INET, s)) except socket.error: return False diff --git a/src/version.py b/src/version.py index bbb1d7295..798922f0a 100644 --- a/src/version.py +++ b/src/version.py @@ -1,3 +1,3 @@ """stick the various versioning attributes in here, so we only have to change them once.""" -version = '0.83.4.1+limnoria (2011-08-18T11:07:25+0200)' +version = '0.83.4.1+limnoria (2011-08-23T16:41:52+0200)' diff --git a/test/test_utils.py b/test/test_utils.py index c4efb4979..da94678e6 100644 --- a/test/test_utils.py +++ b/test/test_utils.py @@ -1,6 +1,6 @@ ### # Copyright (c) 2002-2005, Jeremiah Fincher -# Copyright (c) 2009, James Vega +# Copyright (c) 2009,2011, James Vega # All rights reserved. # # Redistribution and use in source and binary forms, with or without @@ -501,11 +501,9 @@ class NetTest(SupyTestCase): isIP = utils.net.isIP self.failIf(isIP('a.b.c')) self.failIf(isIP('256.0.0.0')) - self.failUnless(isIP('127.1')) self.failUnless(isIP('0.0.0.0')) self.failUnless(isIP('100.100.100.100')) - # This test is too flaky to bother with. - # self.failUnless(utils.isIP('255.255.255.255')) + self.failUnless(isIP('255.255.255.255')) def testIsIPV6(self): f = utils.net.isIPV6