Git Product home page Git Product logo

Comments (3)

grutz avatar grutz commented on August 23, 2024
def oui_lookup(mac_addr='00:00:00:00:00:00', nmap_os_db='/usr/local/share/nmap/nmap-mac-prefixes'):
    """
    Lookup a vendor from the Nmap MAC Prefixes file

    >>> oui_lookup('00:00:00:00:00:00')
    'Xerox'
    >>> oui_lookup('00-00-00-00-00-00')
    'Xerox'
    >>> oui_lookup(-1)
    'Unknown'
    >>> oui_lookup('00:00:00:00:00:00', nmap_os_db='/zxvkjaiwe/9234123/zxcvzxvsadf')
    'Unknown'
    """
    import os
    import mmap

    try:
        oui_fs = open(nmap_os_db, "r")
    except IOError, err:
        return dict(mac_addr='Unknown')

    oui_data = mmap.mmap(oui_fs.fileno(), 0, access=mmap.ACCESS_READ)
    def _lookup(mac_addr, oui_data):
        oui_result = 'Unknown'
        # remove : or - or just accept it as is and be lucky
        if mac_addr.find(':') > -1:
            mac_lookup = "".join(mac_addr.split(':')[:3])
        else:
            mac_lookup = "".join(mac_addr.split('-')[:3])

        if len(mac_lookup) == 6:
            # MAC addresses in nmap db are in upper case and we want start of line (post \n)
            location = oui_data.find('\n' + mac_lookup.upper())
            location += 1   # remove leading \n
            if location > 0:
                oui_result = oui_data[location+7:location+oui_data[location:].find('\n')]

        return oui_result

    result = {}
    if isinstance(mac_addr, list):
        for addr in mac_addr:
            result[addr] = _lookup(addr, oui_data)

    if isinstance(mac_addr, str):
        result[mac_addr] = _lookup(mac_addr, oui_data)

    return result

from kvasir.

grutz avatar grutz commented on August 23, 2024

In controllers/hosts.py:detail():

    if record.f_macaddr:
        oui_res = oui_lookup(record.f_macaddr)
        oui_vendor = oui_res.get(record.f_macaddr, oui_res.get('error', 'None'))
    else:
        oui_vendor = 'None'

add oui_vendor to return dict() and {{=oui_vendor}} to views/hosts/detail.html page.

from kvasir.

grutz avatar grutz commented on August 23, 2024

added in 50ad129

from kvasir.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.