Пример #1
0
def update_oui():
    if interface.utils.file_exists(
            "./databases/oui.db") and core.globals.ouidb_conn is not None:
        connection = core.globals.ouidb_conn
        cursor = connection.cursor()
        #Truncate database
        print_blue("Truncating oui table")
        cursor.execute("""DROP TABLE oui""")
        cursor.execute("""CREATE TABLE oui (
                             id INTEGER PRIMARY KEY NOT NULL,
                             oui TEXT UNIQUE,
                             name TEXT)""")
        print_blue("Downloading new OUI file")
        interface.utils.wget("http://standards.ieee.org/regauth/oui/oui.txt",
                             "./output/tmp_oui.txt")
        file = open("./output/tmp_oui.txt", "r")
        regex = re.compile(r"\(base 16\)")
        for line in file:
            if regex.search(line) is not None:
                line = "".join(line.split("\t"))
                line = line.split("(")
                oui = line[0].replace(" ", "")
                company = line[1].split(")")[1]
                company = company.replace("\n", "")
                if company == " ":
                    company = "Private"
                try:
                    cursor.execute("INSERT INTO oui (oui, name) VALUES (?, ?)",
                                   [oui, company])
                    connection.commit()
                except Exception as e:
                    #CONRAD CORP. and CERN + ROYAL MELBOURNE INST OF TECH share oui, this should be considered
                    #print(e)
                    #print(oui + " " + company)
                    #SELECT name FROM oui.oui WHERE oui = oui
                    #UPDATE oui.oui SET name = name+" OR "+company WHERE oui=oui
                    pass

        #Add a few OUIs manually (from NMAP oui file)
        cursor.execute(
            "INSERT INTO oui (oui, name) VALUES ('525400', 'QEMU Virtual NIC')"
        )
        cursor.execute(
            "INSERT INTO oui (oui, name) VALUES ('B0C420', 'Bochs Virtual NIC')"
        )
        cursor.execute(
            "INSERT INTO oui (oui, name) VALUES ('DEADCA', 'PearPC Virtual NIC')"
        )
        cursor.execute(
            "INSERT INTO oui (oui, name) VALUES ('00FFD1', 'Cooperative Linux virtual NIC')"
        )
        connection.commit()
        try:
            os.remove("./output/tmp_oui.txt")
        except OSError:
            pass
Пример #2
0
def update_oui():
    if interface.utils.file_exists("./databases/oui.db") and core.globals.ouidb_conn is not None:
            connection = core.globals.ouidb_conn
            cursor = connection.cursor()
            # Truncate database
            print_blue("Truncating oui table")
            cursor.execute("""DROP TABLE oui""")
            cursor.execute("""CREATE TABLE oui (
                             id INTEGER PRIMARY KEY NOT NULL,
                             oui TEXT UNIQUE,
                             name TEXT)""")
            # This is very important, sqlite3 creates transaction for every INSERT/UPDATE/DELETE
            # but can handle only dozen of transactions at a time.
            # BEGIN guarantees that only one transaction will be used.
            # Now the DB rebuild should take only seconds
            cursor.execute('begin')
            print_blue("Downloading new OUI file")
            path = interface.utils.wget("http://standards.ieee.org/regauth/oui/oui.txt", "./output/tmp_oui.txt")
            if not path:
                print_error('Failed to download')
                return
            file = open(path, "r")
            regex = re.compile(r"\(base 16\)")
            for line in file:
                if regex.search(line) is not None:
                    line = "".join(line.split("\t"))
                    line = line.split("(")
                    oui = line[0].replace(" ", "")
                    company = line[1].split(")")[1]
                    company = company.replace("\n", "")
                    if company == " ":
                        company = "Private"
                    try:
                        cursor.execute("INSERT INTO oui (oui, name) VALUES (?, ?)", [oui, company])
                        status = '\rInserting {0}:{1}'
                        sys.stdout.write(status.format(company, oui))
                    except Exception as e:
                        # CONRAD CORP. and CERN + ROYAL MELBOURNE INST OF TECH share oui, this should be considered
                        # print(e)
                        # print(oui + " " + company)
                        # SELECT name FROM oui.oui WHERE oui = oui
                        # UPDATE oui.oui SET name = name+" OR "+company WHERE oui=oui
                        pass
            print()

            # Add a few OUIs manually (from NMAP oui file)
            cursor.execute("INSERT INTO oui (oui, name) VALUES ('525400', 'QEMU Virtual NIC')")
            cursor.execute("INSERT INTO oui (oui, name) VALUES ('B0C420', 'Bochs Virtual NIC')")
            cursor.execute("INSERT INTO oui (oui, name) VALUES ('DEADCA', 'PearPC Virtual NIC')")
            cursor.execute("INSERT INTO oui (oui, name) VALUES ('00FFD1', 'Cooperative Linux virtual NIC')")
            connection.commit()
            try:
                os.remove("./output/tmp_oui.txt")
            except OSError:
                pass
Пример #3
0
 def do_update(self, e):
     args = e.split(' ')
     if args[0] == "oui":
         print_blue("Updating OUI DB. Database rebuild may take several minutes.")
         # print_blue("Do you wish to continue? (y/n)")
         # Add if here
         updater.update_oui()
         print_blue("OUI database updated successfully.")
     elif args[0] == "force":
         print_blue("Discarding local changes and updating REXT")
         updater.update_rext_force()
     elif args[0] == "":
         print_blue("Updating REXT please wait...")
         updater.update_rext()
         print_blue("Update successful")
Пример #4
0
 def do_update(self, e):
     args = e.split(' ')
     if args[0] == "oui":
         print_blue(
             "Updating OUI DB. Database rebuild may take several minutes.")
         #print_blue("Do you wish to continue? (y/n)")
         #Add if here
         updater.update_oui()
         print_blue("OUI database updated successfully.")
     elif args[0] == "force":
         print_blue("Discarding local changes and updating REXT")
         updater.update_rext_force()
     elif args[0] == "":
         print_blue("Updating REXT please wait...")
         updater.update_rext()
         print_blue("Update successful")
Пример #5
0
def update_oui():
    if interface.utils.file_exists("./databases/oui.db") and core.globals.ouidb_conn is not None:
        connection = core.globals.ouidb_conn
        cursor = connection.cursor()
        # Truncate database
        print_blue("Truncating oui table")
        cursor.execute("""DROP TABLE oui""")
        cursor.execute(
            """CREATE TABLE oui (
                             id INTEGER PRIMARY KEY NOT NULL,
                             oui TEXT UNIQUE,
                             name TEXT)"""
        )
        print_blue("Downloading new OUI file")
        interface.utils.wget("http://standards.ieee.org/regauth/oui/oui.txt", "./output/tmp_oui.txt")
        file = open("./output/tmp_oui.txt", "r")
        regex = re.compile(r"\(base 16\)")
        for line in file:
            if regex.search(line) is not None:
                line = "".join(line.split("\t"))
                line = line.split("(")
                oui = line[0].replace(" ", "")
                company = line[1].split(")")[1]
                company = company.replace("\n", "")
                if company == " ":
                    company = "Private"
                try:
                    cursor.execute("INSERT INTO oui (oui, name) VALUES (?, ?)", [oui, company])
                    connection.commit()
                except Exception as e:
                    # CONRAD CORP. and CERN + ROYAL MELBOURNE INST OF TECH share oui, this should be considered
                    # print(e)
                    # print(oui + " " + company)
                    # SELECT name FROM oui.oui WHERE oui = oui
                    # UPDATE oui.oui SET name = name+" OR "+company WHERE oui=oui
                    pass

        # Add a few OUIs manually (from NMAP oui file)
        cursor.execute("INSERT INTO oui (oui, name) VALUES ('525400', 'QEMU Virtual NIC')")
        cursor.execute("INSERT INTO oui (oui, name) VALUES ('B0C420', 'Bochs Virtual NIC')")
        cursor.execute("INSERT INTO oui (oui, name) VALUES ('DEADCA', 'PearPC Virtual NIC')")
        cursor.execute("INSERT INTO oui (oui, name) VALUES ('00FFD1', 'Cooperative Linux virtual NIC')")
        connection.commit()
        try:
            os.remove("./output/tmp_oui.txt")
        except OSError:
            pass
Пример #6
0
def update_oui():
    if interface.utils.file_exists(
            "./databases/oui.db") and core.globals.ouidb_conn is not None:
        connection = core.globals.ouidb_conn
        cursor = connection.cursor()
        # Truncate database
        print_blue("Truncating oui table")
        cursor.execute("""DROP TABLE oui""")
        cursor.execute("""CREATE TABLE oui (
                             id INTEGER PRIMARY KEY NOT NULL,
                             oui TEXT UNIQUE,
                             name TEXT)""")
        # This is very important, sqlite3 creates transaction for every INSERT/UPDATE/DELETE
        # but can handle only dozen of transactions at a time.
        # BEGIN guarantees that only one transaction will be used.
        # Now the DB rebuild should take only seconds
        cursor.execute('begin')
        print_blue("Downloading new OUI file")
        path = interface.utils.wget(
            "http://standards.ieee.org/regauth/oui/oui.txt",
            "./output/tmp_oui.txt")
        if not path:
            print_error('Failed to download')
            return
        file = open(path, "r")
        regex = re.compile(r"\(base 16\)")
        for line in file:
            if regex.search(line) is not None:
                line = "".join(line.split("\t"))
                line = line.split("(")
                oui = line[0].replace(" ", "")
                company = line[1].split(")")[1]
                company = company.replace("\n", "")
                if company == " ":
                    company = "Private"
                try:
                    cursor.execute("INSERT INTO oui (oui, name) VALUES (?, ?)",
                                   [oui, company])
                    status = '\rInserting {0}:{1}'
                    sys.stdout.write(status.format(company, oui))
                except Exception as e:
                    # CONRAD CORP. and CERN + ROYAL MELBOURNE INST OF TECH share oui, this should be considered
                    # print(e)
                    # print(oui + " " + company)
                    # SELECT name FROM oui.oui WHERE oui = oui
                    # UPDATE oui.oui SET name = name+" OR "+company WHERE oui=oui
                    pass
        print()

        # Add a few OUIs manually (from NMAP oui file)
        cursor.execute(
            "INSERT INTO oui (oui, name) VALUES ('525400', 'QEMU Virtual NIC')"
        )
        cursor.execute(
            "INSERT INTO oui (oui, name) VALUES ('B0C420', 'Bochs Virtual NIC')"
        )
        cursor.execute(
            "INSERT INTO oui (oui, name) VALUES ('DEADCA', 'PearPC Virtual NIC')"
        )
        cursor.execute(
            "INSERT INTO oui (oui, name) VALUES ('00FFD1', 'Cooperative Linux virtual NIC')"
        )
        connection.commit()
        try:
            os.remove("./output/tmp_oui.txt")
        except OSError:
            pass