MAC address randomizer - MAC Address does not change? - bash

I've tried to create a small and basic bash script to change my MAC address on MacOS, upon reboot. The script trows no errors, however nor does it change my mac address.
The script:
#!/bin/bash
sudo echo "Welcome"
preAddress="$(ifconfig en0|grep ether)"
numZero=2
numOne=$(( ( RANDOM % 9 ) + 0 ))
numTwo="$(openssl rand -hex 1)"
numThree="$(openssl rand -hex 1)"
numFour="$(openssl rand -hex 1)"
numFive="$(openssl rand -hex 1)"
numSix="$(openssl rand -hex 1)"
newAddress="$numZero$numOne:$numTwo:$numThree:$numFour:$numFive:$numSix"
sudo /System/Library/PrivateFrameworks/Apple80211.framework/Resources/airport --disassociate
sudo ifconfig en0 ether $newAddress
networksetup -detectnewhardware
sudo ifconfig en0 up
echo "MAC Address changed to: $newAddress from$preAddress"
I've re-used some code, originally posted here: Post 1 user: seren/user137369, Post 2 User: Luke Exton, Post 3 User: OrangeTux/py4on.
In short, the script creates a set of variables which all contains a random number. These variables are formatted as a MAC Address in another variable. I then change (or at least try to) the current MAC address to the random one.
But when I run this, I see no change under Network>Advanced in system settings or if I run "ifconfig" in the terminal?
I've also tried to just copy in the following to the terminal, but no dice..:
sudo ifconfig en0 down
sudo ifconfig en0 ether 27:ab:29:b9:be:ef
sudo ifconfig en0 up
I simply cannot figure out why this does not work.. Any help is very appreciated!

Related

Netcat command: Unknown IP address

I have two laptops that each has connected to the Internet by landline (two different lines/modem). One is Mac and the other is Windows. I want to send a message from Windows to the Mac.
I installed NetCat on Mac using, brew install netcat, based on this page.
I installed NetCat on Windows based on this page.
I ran following command in Mac terminal in order to see what is my IP address: $ ipconfig getifaddr en0 it printed: 169.254.136.39
In Mac terminal: $ nc -u -l -p 4444. Seems it is ready for incomming messages.
In Windows terminal: $ nc -u 169.254.136.39 4444. I get a new line and I assume connection has established. However, when I enter a message and hit Enter, nothing happens :(
When I replace above command with nc -u -v -n 169.254.136.39 4444 in Windows and nc -u -l -n -p 4444 in Mac, then I get: (UNKNOWN) [169.254.136.39] 4444 (?) open
I have no idea what is wrong? I confirm Firewal is off on my Mac.

Check if arp table contains certain MAC address

I want to build a .sh script for a tomatousb router that would be launched once a minute and send requests to telegrambot api once the certain mac address is added or removed from the router's arp table.
I want to store the last state (if the mac address was found) in the env variable, but I have no clue how to check for the address.
I would normally do
if [(arp -a | grep aabbccdd)!=null] then
/usr/bin/wget https://api.telegram.org/... --no-check-certificate
but that doesn't seem to work..
arp -a | egrep -o '(\w{1,2}:){5}\w{1,2}' will return all the available MAC addresses.

Finding the correct network interface for VirtualBox instance spun up by docker-machine on OSX

Im trying to automate a docker run shell script that needs to spin up an X11 app running on a docker-machine VM with virtualbox driver on OSX/mac. To get the x11 app to forward the X11 display to the desktop host i need to get the ip address of the correct vboxnet* (i assume) network interface (not the docker ip) and export that ip into the docker container.
what i am currently doing is assuming that the docker-machine VM ip is tied to the "vboxnet1" interface name and regexp'ing it out of ifconfig.
i see that the virtualbox DHCP process that spins up when i start docker-machine has a trunk name that corresponds to the interface i want - but again this seems like an assumption and i would think there is some command i could run to be certain which address it is so my docker run script will work on any machine.
/Applications/VirtualBox.app/Contents/MacOS/VBoxNetDHCP --ip-address
192.168.99.2 --lower-ip 192.168.99.100 --mac-address XXXXXXXXXXX
--netmask 255.255.255.0 --network HostInterfaceNetworking-vboxnet1
--trunk-name vboxnet1 --trunk-type netadp --upper-ip 192.168.99.254
Is there a way to definitively determine which network interface to find the ip address?
This bash script seems to work on OSX machines:
#!/bin/bash
CONFIG=$( ifconfig | grep -A 2 'vboxnet1')
regex="([0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3})"
if [[ $CONFIG =~ $regex ]]; then
DISPLAY=${BASH_REMATCH[1]}
DISPLAY+=":0"
fi
ifconfig $(route -n get $(docker-machine ip default) | grep interface: | awk '{print $2}') | grep inet | awk '{print $2}'

BASH on OS X: Why does this script not work?

I wrote the following BASH script to change my MAC address back to the normal one after I am done using a spoofed MAC address:
sudo ifconfig en1 ether 00:11:22:33:44:55
It works. However, the following code doesn't work:
mac=$(cat /volumes/KYLE-OSX/mac.txt)
sudo ifconfig en1 ether $mac
I am given the following error message:
ifconfig: can't set link-level netmask or broadcast
I am unable to predict what the MAC address is going to be, so I need to be able to use any possible MAC address in the 'sudo ifconfig en1 ether' statement.
The fundamental problem was diagnosed in comments already -- the file contains more than just the MAC address. Here's a simple workaround for that.
mac=$(grep -Eo '\<[0-9a-f]{2}(:[0-9a-f]{2}){5}\>' /Volumes/KYLE-OSX/mac.txt)

How do I get remote login IP to my machine from terminal on Mac OS?

I want to be able to obtain the IP from a bash script. The same one I obtain going to System Preferences => Sharing => Remote Login.
Does anyone know how to do it? I am running Mac OS 10.9.4.
Updated Again
If you just want the IP addresses, you can do this:
ifconfig -a | awk '/inet /{print $2}'
Updated
You could try scutil like this:
scutil --get HostName
or maybe this:
scutil --get LocalHostName
or maybe this:
scutil --get ComputerName
Original Answer
Use hostname, like this:
hostname
Or, if you want it in a variable to use with ssh
address=$(hostname)
ssh $address

Resources