示例#1
0
class Device:

    def __init__(self, name, ip_address, mac_address, ):
        self.name = name
        self.ip = ip_address
        self.mac = MAC(mac_address)

    def __str__(self):
        return str(self.__dict__)

    def change_mac(self):
        self.stop()
        self.mac.reset_mac()
        command = ['ifconfig', self.name, 'hw', 'ether', str(self.mac)]
        code = call(command, stdout=DEVNULL, stderr=STDOUT)
        if code > 1:
            self.change_mac()
        self.start()

    def stop(self):
        command = ['ifconfig', self.name, "down"]
        code = call(command)
        if code > 1:
            raise CalledProcessError(code, command)

    def start(self):
        command = ['ifconfig', self.name, "up"]
        code = call(command)
        if code > 1:
            raise CalledProcessError(code, command)