wlan_swap.sh 1.0 KB

1234567891011121314151617181920212223242526272829303132333435
  1. #!/bin/bash
  2. if (( $EUID != 0 )); then
  3. echo "This must be run as root. Try 'sudo bash $0'."
  4. exit 1
  5. fi
  6. echo "Swap wlan0 and wlan1"
  7. IFACE=wlan0
  8. read MAC </sys/class/net/$IFACE/address
  9. if ! [ -f /etc/udev/rules.d/70-my_network_interfaces.rules ]
  10. then
  11. echo "file not exist => install it.."
  12. echo ""
  13. else
  14. echo "file exist => remove it and install it again..."
  15. echo ""
  16. rm /etc/udev/rules.d/70-my_network_interfaces.rules
  17. fi
  18. cat <<'EOF'>> /etc/udev/rules.d/70-my_network_interfaces.rules
  19. # Built-in wifi interface used in hostapd - identify device by MAC address
  20. SUBSYSTEM=="net", ACTION=="add", ATTR{address}=="XXX", NAME="wlan1"
  21. EOF
  22. sudo sed -i -e "s/XXX/$MAC/g" /etc/udev/rules.d/70-my_network_interfaces.rules
  23. echo "Actuel wlan0 MAC address is : $MAC"
  24. echo "After reboot wlan0 will swapped to wlan1 and wlan1 to wlan0"
  25. echo "check the config file and double check is what you want:"
  26. echo ""
  27. cat /etc/udev/rules.d/70-my_network_interfaces.rules
  28. echo ""
  29. echo "if it's ok, reboot...otherwize edit the file /etc/udev/rules.d/70-my_network_interfaces.rules"
  30. echo