Merge lp:~mgorven/ibid/oui into lp:~ibid-core/ibid/old-trunk-1.6

Proposed by Michael Gorven
Status: Merged
Approved by: Stefano Rivera
Approved revision: not available
Merged at revision: not available
Proposed branch: lp:~mgorven/ibid/oui
Merge into: lp:~ibid-core/ibid/old-trunk-1.6
Diff against target: 39 lines (+19/-1)
1 file modified
ibid/plugins/sysadmin.py (+19/-1)
To merge this branch: bzr merge lp:~mgorven/ibid/oui
Reviewer Review Type Date Requested Status
marcog (community) Approve
Stefano Rivera Approve
Keegan Carruthers-Smith Approve
Review via email: mp+19259@code.launchpad.net
To post a comment you must log in.
Revision history for this message
marcog (marco-gallotta) wrote :

Query: reload sysadmin
DEBUG:core.reloader:Loading Processor: sysadmin.AptFile
ERROR:core.reloader:Couldn't instantiate AptFile processor of sysadmin plugin
Traceback (most recent call last):
  File "./ibid/core.py", line 235, in load_processor
    ibid.processors.append(klass(name))
  File "./ibid/plugins/__init__.py", line 80, in __init__
    self.setup()
  File "./ibid/plugins/sysadmin.py", line 118, in setup
    raise Exception("Cannot locate apt-file executable")
Exception: Cannot locate apt-file executable
Response: Couldn't reload sysadmin

Not sure if we usually implement workarounds for this, but this is failing because another feature in this plugin has a dependency that isn't installed.

+ @match(r'^(?:(?:mac|oui|ether|ether(?:net)?(?:\s*code)?)\s+)?((?:(?:[0-9a-f]{2}[:-]?){3}){1,2})$')

You can remove the "ether|" as it's caught by the one that follows.

Do you want to allow a trailing [:-]? (e.g. 11:22:33: matches)

Query: 112233
Response: I don't know who that belongs to

That is very unexpected if the user was not trying to lookup a mac address. I would require the 11:22:33 format (even disallowing 11-22-33 because that looks like an expression) if the leading word (mac, ether, etc.) is left out.

review: Needs Fixing
Revision history for this message
marcog (marco-gallotta) wrote :

+ oui = mac.replace('-', '').replace(':', '').upper()[:6]

Why the [:6]?

Perhaps use re.sub to strip [-:] in a single call.

Revision history for this message
marcog (marco-gallotta) wrote :

+ oui = mac.replace('-', '').replace(':', '').upper()[:6]

Why the [:6]?

Perhaps use re.sub to strip [-:] in a single call.

review: Needs Fixing
Revision history for this message
Michael Gorven (mgorven) wrote :

> Why the [:6]?

The first 6 hex characters identify the manufacturer.

> Perhaps use re.sub to strip [-:] in a single call.

It's probably more efficient to do 2 replaces() ;-)

Revision history for this message
Stefano Rivera (stefanor) wrote :

> Not sure if we usually implement workarounds for this, but this is failing because another feature in this plugin has a dependency that isn't installed.

We don't, but that is probably out of scope for this review. There is a plan to rework dependency handling, but in the meantime we just hack around it.

Revision history for this message
Keegan Carruthers-Smith (keegan-csmith) wrote :

> Not sure if we usually implement workarounds for this, but this is failing
> because another feature in this plugin has a dependency that isn't installed.

I agree, why should everything fail just because of that? Especially since this will not be necessarily run on a debianesque machine.

> + @match(r'^(?:(?:mac|oui|ether|ether(?:net)?(?:\s*code)?)\s+)?((?:(?:[0-9a-f]
> {2}[:-]?){3}){1,2})$')
>
> You can remove the "ether|" as it's caught by the one that follows.

Agreed.

Otherwise I approve.

review: Approve
Revision history for this message
Stefano Rivera (stefanor) wrote :

worksforme

review: Approve
lp:~mgorven/ibid/oui updated
888. By Michael Gorven

Require that MAC address contains colons when not prefixed with keyword.

889. By Michael Gorven

Merge from trunk to resolve conflict.

Revision history for this message
Michael Gorven (mgorven) wrote :

> That is very unexpected if the user was not trying to lookup a mac address.
> I would require the 11:22:33 format (even disallowing 11-22-33 because
> that looks like an expression) if the leading word (mac, ether, etc.) is
> left out.

r888. It does allow anything from 3 to 6 groups, but I think that's okay.

Revision history for this message
Max Rabkin (max-rabkin) wrote :

> name = u' '.join(word.capitalize() for word in name.split(' '))

I think you meant "name = name.title()"

Revision history for this message
Michael Gorven (mgorven) wrote :

> I think you meant "name = name.title()"

Uh, of course ;-) r890

lp:~mgorven/ibid/oui updated
890. By Michael Gorven

<3 Python

Revision history for this message
Michael Gorven (mgorven) wrote :

r891 closes the file properly.

lp:~mgorven/ibid/oui updated
891. By Michael Gorven

Let's rather not leak file descriptors.

Revision history for this message
marcog (marco-gallotta) wrote :

> > That is very unexpected if the user was not trying to lookup a mac address.
> > I would require the 11:22:33 format (even disallowing 11-22-33 because
> > that looks like an expression) if the leading word (mac, ether, etc.) is
> > left out.
>
> r888. It does allow anything from 3 to 6 groups, but I think that's okay.

Getting very nitpicky, but this is a bit weird:

Query: mac 123456
Response: I don't know who that belongs to
Query: mac 1234567
Response: Excuse me?
Query: mac 12345678
Response: I don't know who that belongs to

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'ibid/plugins/sysadmin.py'
2--- ibid/plugins/sysadmin.py 2010-02-09 14:39:23 +0000
3+++ ibid/plugins/sysadmin.py 2010-02-13 12:16:18 +0000
4@@ -2,11 +2,12 @@
5 # Released under terms of the MIT/X/Expat Licence. See COPYING for details.
6
7 import os
8+import re
9 from subprocess import Popen, PIPE
10
11 from ibid.plugins import Processor, match
12 from ibid.config import Option
13-from ibid.utils import file_in_path, unicode_output, human_join
14+from ibid.utils import file_in_path, unicode_output, human_join, cacheable_download
15
16 help = {}
17
18@@ -181,4 +182,21 @@
19 if index:
20 event.addresponse(output[index+1].strip())
21
22+help ['mac'] = u'Finds the organization owning the specific MAC address.'
23+class Mac(Processor):
24+ u"""mac <address>"""
25+ feature = 'mac'
26+
27+ @match(r'^((?:mac|oui|ether(?:net)?(?:\s*code)?)\s+)?((?:(?:[0-9a-f]{2}(?(1)[:-]?|:))){2,5}[0-9a-f]{2})$')
28+ def lookup_mac(self, event, _, mac):
29+ oui = mac.replace('-', '').replace(':', '').upper()[:6]
30+ ouis = open(cacheable_download('http://standards.ieee.org/regauth/oui/oui.txt', 'sysadmin/oui.txt'))
31+ match = re.search(r'^%s\s+\(base 16\)\s+(.+?)$' % oui, ouis.read(), re.MULTILINE)
32+ ouis.close()
33+ if match:
34+ name = match.group(1).decode('utf8').title()
35+ event.addresponse(u"That belongs to %s", name)
36+ else:
37+ event.addresponse(u"I don't know who that belongs to")
38+
39 # vi: set et sta sw=4 ts=4:

Subscribers

People subscribed via source and target branches