#! /usr/bin/env python import subprocess import dhcp_client def create_viface(iface, viface, mac): if subprocess.call(['ip', 'link', 'add', 'link', iface, viface, 'address', mac, 'type', 'macvlan']) != 0: return False if subprocess.call(['ip', 'link', 'dev', 'set', viface, 'up']) != 0: return False return True def remove_viface(viface): return subprocess.call(['ip', 'link', 'del', viface]) == 0 iface = 'em1' viface = 'vmac' mac = '6c:3b:e5:1f:96:46' if not create_viface(iface, viface, mac): print('Failed to create virtual interface') quit(1) dh = dhcp_client.DhcpClient() offer = dh.get_offer(mac, viface) if offer == None: print('DHCP client timeout') else: print(offer.str()) if not remove_viface(viface): printf('Failed to remove virtual interface') quit(4)