[Optimus One, P500, V General] null0R:
Hi.

I wasn't too sure, if I should post this into the development area, I think it fits more into general.

Introduction

According to this thread, I tried to write a little script which lets one spoof his wi-fi MAC address unindependently from any adb shell or usb connection. It's very experimental and might not work that properly. If I try it at home, my router somehow shuts down any incoming wi-fi connection in the whole network and turns the internet off. :/ But the script itself actually SEEMS to change the MAC address (according to what the wi-fi settings say).

I am not responsible for any damage to your phone. However, you can reset the changed MAC address anyway, if something bad happens.

Please note, that you are only allowed to use this script in those networks where you have the permission to do so. Especially the use of the "MAC takeover" function might be illegal in different networks.

Requirements

You will need SL4A (Android Scripting Environment) and PFA (PHP for Android). Check out: http://www.phpforandroid.net/#requirements

The script

<?php
// config: config-file and tmp-file
$cnf = "/etc/wl/nvram.txt";
$tmp = "/sdcard/nvram-tmp.txt";

// this is my very dirty solution to replace the actual config file with a new edited one. root needed. might not work everywhere.
$cmd = 'su -c "mount -o rw,remount -t yaffs2 /dev/block/mtdblock4 /system; mv -f \"'.$tmp.'\" \"'.$cnf.'\"; chmod 644 \"'.$cnf.'\"; mount -o ro,remount -t yaffs2 /dev/block/mtdblock4 /system"';

// access android api
require_once("Android.php");
$droid = new Android();

// get config file src
$src = file_get_contents($cnf);

// check, if mac address was already spoofed before
preg_match("|macaddr=([a-f0-9]{2}:[a-f0-9]{2}:[a-f0-9]{2}:[a-f0-9]{2}:[a-f0-9]{2}:[a-f0-9]{2})|i", $src, $res);
$spoofed = false;
$macaddr = "13:57:9B:DF:13:37";
if(isset($res[1]))
{
$spoofed = true;
$macaddr = $res[1];
}

// pre-configurations
$title = "LG-OO-P500 MAC Spoofer";
$action = "start";

// main loop for actions
while(true)
{
switch($action)
{
// start
case "start":
$msg = "Your MAC address is currently set on default.";

// currently spoofed mac address?
if($spoofed)
{
$msg = "Your currently spoofed MAC address is: ".$macaddr;
}
$droid->makeToast($msg);

// create dialog
$droid->dialogCreateAlert($title);
$droid->dialogSetItems(array("Change MAC address", "MAC takeover", "Reset MAC address", "Exit"));
$droid->dialogShow();

// determine next action
$res = $droid->dialogGetResponse();
$actions = array("spoof", "scan", "reset", "exit");
$action = $actions[$res["result"]->item];
$droid->dialogDismiss();
break;

// spoof and reset action
case "spoof": case "scan": case "reset":
// get user input for new mac addr
switch($action)
{
case "spoof":
while(true)
{
$res = $droid->dialogGetInput($title, "Insert new MAC address", $macaddr);
$macaddr = strtoupper($res["result"]);
if(preg_match("|[a-f0-9]{2}:[a-f0-9]{2}:[a-f0-9]{2}:[a-f0-9]{2}:[a-f0-9]{2}:[a-f0-9]{2}|i", $macaddr))
{
break;
}
$droid->makeToast("Invalid MAC address. (example: 00:00:00:00:00:00 to FF:FF:FF:FF:FF:FF)");
}
$rpl = "macaddr=".$macaddr;
break;
case "scan":
$droid->dialogCreateSpinnerProgress("Now scanning network...");
// scan for MACs and filter ip and MAC addresses from the output
exec("arp -a", $out);
preg_match_all("|\(([0-9]+\.[0-9]+\.[0-9]+\.[0-9]+)\) at ([a-f0-9]{2}:[a-f0-9]{2}:[a-f0-9]{2}:[a-f0-9]{2}:[a-f0-9]{2}:[a-f0-9]{2})|i", strtoupper(implode("\r\n", $out)), $res);
$droid->dialogDismiss();
// create new array
$arr = array();
for($i = 0; $i != count($res[1]); $i++)
{
$arr["list"][] = $res[1][$i]."\n=> ".$res[2][$i];
$arr["ip"][] = $res[1][$i];
$arr["mac"][] = $res[2][$i];
}
$droid->dialogCreateAlert("Found ".count($arr)." individuals... please choose:");
$droid->dialogSetItems($arr["list"]);
$droid->dialogShow();
$res = $droid->dialogGetResponse();
$rpl = "macaddr=".$arr["mac"][$res["result"]->item];
break;
case "reset": default:
$rpl = null;
break;
}
// edit src
($spoofed || empty($rpl)) ? $src = rtrim(preg_replace("|macaddr=.*|i", $rpl, $src)) : $src = rtrim($src)."\n".$rpl;
// disable wifi
$droid->toggleWifiState(false);

// save tmp file
$h = fopen($tmp, "w");
fwrite($h, $src);
fclose($h);

// overwrite with root privileges
exec($cmd);

$droid->makeToast("Operation complete.");
$action = "exit";
break;

// exit
case "exit":
// enable wlan and exit
$droid->toggleWifiState(true);
$droid->exit();
exit();
break;
}
}

I am really not sure, if it is going to work for you. I tested it under devoid #forever (CM7, 2.3.4). Maybe other ROMs and other smartphones are going to behave different. And to be honest, for me it didn't work that good either until now.

If you are having trouble, you can also try to reboot after spoofing.

Have fun trying.