Пример #1
0
 def mac_mapper(self, unknown_mac):
     zipfile = os.path.dirname(os.path.dirname(__file__))
     with ZipFile(zipfile) as z:
         reader = z.open('../install/addr_database.csv')
         reader - csv.reader(f, delimiter=',')
         for row in reader:
             if unknown_mac.startswith(row[0]):
                 logger.debug('{} is from the Company: {}'.format(unknown_mac, row[1]))
Пример #2
0
    def __transfer_file(self, client_socket):
        """
        This function serves the file socket's coming requests.
        """
        logger.info("TCP - started file_transferring")
        try:
            # opens the specified file in a read only binary form
            transfer_file = open("{}/{}".format(self.data_dir, "rootfs.tgz"),
                                 "rb")
            data = transfer_file.read()
            logger.debug("TCP - read rootfs.tgz")

            if data:
                # send the data
                logger.debug("TCP - sending rootfs.tgz")
                client_socket.send(data)
                logger.debug("TCP - finished sending rootfs.tgz")
        except:
            logger.error(traceback.print_exc())

        logger.info("TCP - finished file_transferring")
        client_socket.close()
        transfer_file.close()
Пример #3
0
        result = varBinds[0].prettyPrint()
        return result.split(" = ")[1]


def mac_in_decimal(mac_address):
    parts = []
    for part in mac_address.split(":"):
        parts.append(str(int(part, 16)))
    return ".".join(parts)


if __name__ == "__main__":
    if len(sys.argv) != 4:
        logger.info(
            "Usage: '$ python3 findport.py XX:XX:XX:XX:XX:XX SWITCH_ADDRESS VLAN_NUMBER'"
        )
        sys.exit(1)

    mac_address = sys.argv[1]
    switch_address = sys.argv[2]
    vlan_number = sys.argv[3]

    try:
        port = find_port(mac_address, switch_address, vlan_number)
        if port is None:
            raise Exception('Oops!')
        logger.debug(port)
    except Exception as e:
        # print(e)
        logger.warning("{} not found".format(mac_address))