Nevar pievienot vairāk kā 25 tēmas Tēmai ir jāsākas ar burtu vai ciparu, tā var saturēt domu zīmes ('-') un var būt līdz 35 simboliem gara.

vmac.py 838B

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