|  | @@ -0,0 +1,34 @@
 | 
		
	
		
			
			|  | 1 | +#! /usr/bin/env python
 | 
		
	
		
			
			|  | 2 | +import subprocess
 | 
		
	
		
			
			|  | 3 | +import dhcp_client
 | 
		
	
		
			
			|  | 4 | +
 | 
		
	
		
			
			|  | 5 | +def create_viface(iface, viface, mac):
 | 
		
	
		
			
			|  | 6 | +    if subprocess.call(['ip', 'link', 'add', 'link', iface, viface,
 | 
		
	
		
			
			|  | 7 | +        'address', mac, 'type', 'macvlan']) != 0:
 | 
		
	
		
			
			|  | 8 | +        return False
 | 
		
	
		
			
			|  | 9 | +    if subprocess.call(['ip', 'link', 'dev', 'set', viface, 'up']) != 0:
 | 
		
	
		
			
			|  | 10 | +        return False
 | 
		
	
		
			
			|  | 11 | +    return True
 | 
		
	
		
			
			|  | 12 | +
 | 
		
	
		
			
			|  | 13 | +def remove_viface(viface):
 | 
		
	
		
			
			|  | 14 | +    return subprocess.call(['ip', 'link', 'del', viface]) == 0
 | 
		
	
		
			
			|  | 15 | +
 | 
		
	
		
			
			|  | 16 | +iface = 'em1'
 | 
		
	
		
			
			|  | 17 | +viface = 'vmac'
 | 
		
	
		
			
			|  | 18 | +mac = '6c:3b:e5:1f:96:46'
 | 
		
	
		
			
			|  | 19 | +
 | 
		
	
		
			
			|  | 20 | +if not create_viface(iface, viface, mac):
 | 
		
	
		
			
			|  | 21 | +    print('Failed to create virtual interface')
 | 
		
	
		
			
			|  | 22 | +    quit(1)
 | 
		
	
		
			
			|  | 23 | +
 | 
		
	
		
			
			|  | 24 | +dh = dhcp_client.DhcpClient()
 | 
		
	
		
			
			|  | 25 | +offer = dh.get_offer(mac, viface)
 | 
		
	
		
			
			|  | 26 | +
 | 
		
	
		
			
			|  | 27 | +if offer == None:
 | 
		
	
		
			
			|  | 28 | +    print('DHCP client timeout')
 | 
		
	
		
			
			|  | 29 | +else:
 | 
		
	
		
			
			|  | 30 | +    print(offer.str())
 | 
		
	
		
			
			|  | 31 | +
 | 
		
	
		
			
			|  | 32 | +if not remove_viface(viface):
 | 
		
	
		
			
			|  | 33 | +    printf('Failed to remove virtual interface')
 | 
		
	
		
			
			|  | 34 | +    quit(4)
 |