I've been making a BASh script that changes your MAC Address to that of any manufacturer of your choice from a list. At the last part of the script that is run, it stops before finishing. Here is the code for that part:

function spoofUseMAC() {

  read -p "[*] $($stopAllFX; $bgBlack; $white)Enter the number code for manufacturer: >>> " num
  echo "[-] Generating MAC Address"
  num=$( expr $num - 1 )
  declare -a array
  while read -r; do
    array+=( "$REPLY" )
  done < addr.txt
  end=$( for i in {1..6} ; do echo -n ${hexchars:$(( $RANDOM % 16 )):1} ; done | sed -e 's/\(..\)/:\1/g' )
  echo "[-] MAC Address generated !"
  echo "[-] Using address: $macAddress"

  $skyBlue; $bold; echo
  read -p "[*] $($stopAllFX; $bgBlack; $white)Select an interface: >>> " iface
  $yellow; echo "[-] $iface selected !"
  $white; echo  "[-] Disabling $iface ..."
  ifconfig $iface down
  ifconfig '$iface' hw ether '$macAddress'
  echo "[-] MAC Address spoofed !"
  sleep 1
  echo "[-] Enabling $iface ..."
  ifconfig '$iface' up
  echo "[-] $iface enabled !"
  echo "[-] Using address: $macAddress"


function spoofSearchAgainOrNot() {

  $bold; $white; echo
  echo "[*] $($stopAllFX; $bgBlack; $white)Please select an option from the list below:"
  $yellow; $bold; echo "        [$($white)0$($yellow)] $($stopAllFX; $bgBlack; $white)Search again"
  $yellow; $bold; echo "        [$($white)1$($yellow)] $($stopAllFX; $bgBlack; $white)Use one of these"
  read -p ">>> " searchAgainOrNot
  if [[ "$searchAgainOrNot" == "0" ]]; then
  elif [[ "$searchAgainOrNot" == "1" ]]; then


# Spoof, search option selected
function spoofSearch() {

  $bold; echo
  read -p "[*] $($stopAllFX; $bgBlack; $white)Search for a manufacturer: >>> " search
  $blue; awk -F '#' '{printf("%10d %s\n", NR, ":" $1 )}' /usr/bin/oui.txt | grep -i $search



# Spoof
function spoof() {

  echo; $white
  echo "[*] $($stopAllFX; $bgBlack; $white)Please select an option from the list below:"
  $yellow; $bold; echo "        [$($white)0$($yellow)] $($stopAllFX; $bgBlack; $white)Search for a manufacturer"
  $yellow; $bold; echo "        [$($white)1$($yellow)] $($stopAllFX; $bgBlack; $white)Browse for a manufacturer through $($bold)long $($stopAllFX; $bgBlack; $white)list"
  read -p ">>> " searchOrBrowse
  if [[ $searchOrBrowse == "0" ]]; then
  elif [[ $searchOrBrowse == "1" ]]; then


Why can't I use the internet (git clone says could not resolve hostname: github.com) after running this script? And why is it not finishing?

EDIT: This is supposed to work on MacOS and Linux. On MacOS, there is no ip route command, but in Linux, ip route results in: dev wlp1s0  proto kernel scope link  src dev wlp1s0  proto kernel scope link  src  metric 600
  • please add to the question, in text mode, the output of the command 'ip route' – Rui F Ribeiro May 20 '17 at 3:04
  • @RuiFRibeiro Done. – anonymous May 20 '17 at 3:15
  • On Mac OS, you can do netstat -nr. – Rui F Ribeiro May 20 '17 at 3:18
  • 1
    Are you at home, wifi or in a corporate network? – Rui F Ribeiro May 20 '17 at 3:20
  • 2
    If a WiFi router is doing access control based on the MAC address, then I'm not surprised if you can't connect to the Internet. – Kusalananda May 20 '17 at 7:54

Some cards are a bit finicky about changing/spoofing the MAC address.

In OSX the interface MAC address change, in particular the wifi interface, has to be done several times until getting it right e.g. often in a loop, because it must be done in a certain time, I suspect; it often is not assumed at first time with the latest versions of OSX/MacOS.

Notably in OSX the interface/drivers seem to get confused for a couple of seconds after the MAC, however they do recover.

Rare brands won't like it, in some brands you are not advised to change the first 3 octets (the first 6 digits, minus ":"), that are the manufacturer id.

Often you lose your default route, or the router/AP may lose the notion of who you are; while the process should be mostly automatic, in some cases, in Linux you may have to restart the DHCP service after changing the MAC address.

  • 1
    The last part of the code that is visibly run is "[-] Enabling $iface ...", and then it exits... – anonymous May 20 '17 at 11:20

I found the problem: one of the $ifaces had quotes around it when it shouldn't have.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.