[Miscellaneous Android Development] agnostic-apollo:
This Thread has instructions/scripts to randomize or change Wifi Mac Address and also change Wifi hostname of a qualcomm device(if supported)

Tested on LG G3 Stock based MM (Not tested on any other device, will need your feedback)

I Wont Hold Responsibility for any kind of damage to your device

Requirments

1) Root

2) This file should exist "/data/misc/wifi/WCNSS_qcom_wlan_nv.bin" and you have a qualcomm device(not mtk)

3) Busybox (Install latest from playstore)

4) Root File Browser for making backups

5) Script Manager/Terminal Emulator/Tasker to run the scripts

Do This Before Running Any Scripts!

Use a root file browser at go to "/data/wifi/misc/wifi" and find "WCNSS_qcom_wlan_nv.bin" then

1) make a BACKUP of WCNSS_qcom_wlan_nv.bin and to your sd card or internal memory, incase you need to restore them.

Backup the whole "/data/misc" or take a nandroid if you want. The only file modified in my script is WCNSS_qcom_wlan_nv.bin.

2) copy WCNSS_qcom_wlan_nv.bin from "/data/misc/wifi" to "/data" . Explained Later. Used to restore original mac address

Concept:

Basically there are 2 scripts

1) "randomize" script

The Mac Address is taken from your wifi chip and stored in /data/misc/wifi/WCNSS_qcom_wlan_nv.bin when your system boots up.

The WCNSS_qcom_wlan_nv.bin is usually generated on every boot though, in my case atleast.

The randomize script is basically replacing the bytes where your orignal mac is stored with random bytes(Hex).

It also changes your wifi hostname to Anonymous which is by default set as "android-XXX...", the X's are your current android_id

Then it restarts wifi to make the changes take effect

2) "restore" script

The WCNSS_qcom_wlan_nv.bin you copied before to "/data" has your orignal mac restored.

This restore script will copy this back to "/data/misc/wifi" to replace the file changed by randomize script.

It also changes your wifi hostname back to "android-XXX...", the X's are your current android_id

Then it restarts wifi to make the changes take effect

Scripts Download:

http://www.mediafire.com/file/eflrpxovd1whzk9/Mac+Address+Scripts.zip

Instructions on how to run:

The Randomize Script will need to be run on EVERY BOOT to change mac address or you can add it to init.d script.

You need to run scripts with Root permission or it will not work.

If you are using terminal emulator.

copy randomize and restore scripts to "/data", scripts cant be executed from external sd card(Its mounted with noexec)

Run "su" in terminal emulator to get root access.

Run "cd /data" to go to the path where scripts are stored

Run "chmod 755 randomize" and "chmod 755 restore" to change permissions of script and give it executable permission.

Run scripts with "./randomize" or "./restore" if you are in the same folder as the script after running "cd" command.

For Tasker, copy contents of script to Run Shell Action

Moreover if you dont want to have a random mac address each time you run the script, and want a mac address of your choice, it can be easily done by changing the ranomize script.

Open it in test editor

Change "((v1=($RANDOM%126)+32))" to "v1=32".

The number 32 can be replaced with any constant integer number between 32-126. This number will be changed to hex later.

Dont use numbers outside this range as printf cant print those and script will fail.

Do this for all 6 lines(v1 to v6). Use a different number for all if you want.

You can increase the range with some other command but this is what could easily be used without extra support.

And its random enough.

Debugging Info:

I read that for some people if you change the first 6 bytes of the mac address then wifi wont connect to the router.

Didnt happen in my case. If its happened to you then.

remove 3 lines from randomize script(v1 to v3)

"((v1=($RANDOM%126)+32))"

"((v2=($RANDOM%126)+32))"

"((v3=($RANDOM%126)+32))"

and change seek=10 to seek=13 in

"busybox dd of=$wlanBin seek=10 bs=1 conv=notrunc"

You can change (v4-v6) values to constants integers if you dont want random values as previously discussed.

For my LG G3 the mac address is stored from the 10th byte(offset) in WCNSS_qcom_wlan_nv.bin.

The dd command in the randomize script seeks 10 bytes and then starts overwriting the old mac address

"busybox dd of=$wlanBin seek=10 bs=1 conv=notrunc"

I am not sure if other phone's WCNSS_qcom_wlan_nv.bin will also store the mac address from the 10th byte.

You can check that and make appropriate changes to the "seek=10" part.

For how to check this, there is a utility "xxd" to get a hex dump of binary files. Its not available in busybox/android by default.

I have extracted it from termux app.

You can download it here.

copy the xxd file inside the zip to /system/bin and change its permission to 0755

cd to the same folder as a backup of a WCNSS_qcom_wlan_nv.bin binary first.

you can use the command "xxd -ps WCNSS_qcom_wlan_nv.bin dump.txt" to get a hexdump for binary into dump.txt

open dump.txt with a text editor and find your orignal mac address

for example if my mac address was "342de80f9d3c"

the first line of my dump.txt would be

"ffffffff000001020101342de80f9d3c00904cc5123900904cc5123a0090"

note that 34 starts after 10 bytes(2 char=1 byte)

yours could be different, even a different line, whatever your offset, set that as seek of your dd command.

(extra info)

you can manually change your mac address in the dump file and use "xxd -r dump.txt WCNSS_qcom_wlan_nv.bin"

to revert the hexdump back into binary, WCNSS_qcom_wlan_nv.bin will now contain the new mac address

xxd Binary Download:

http://www.mediafire.com/file/60en091lqcvywmm/xxd.zip

credits:

androidiordna at http://android.stackexchange.com/qu...ot-accessible-with-modified-mac-address/60805

https://github.com/termux for xxd binary