1 (edited by orange 2013-06-13 12:47:35)

Topic: macchanger upon boot

Hi,

I'd like to utilize macchanger to randomize my wireless mac address upon boot, i.e. before the wifi initially comes up. So far, I came to the conclusion that /etc/init.d/network would be the best way to introduce a respective macchanger command. But ... Without knowing every fine detail of the OpenWrt boot process (i.e. "insider tricks"), I'd like to ask if you have any other, maybe better, ideas?

Thanks!

EDIT: Thinking about it, I may introduce /etc/rc.d/Sxymacchanger myself (OpenWrt Wiki evolved as I see!). Having the default order ...

lrwxrwxrwx    1 root     root            14 Jun  8  2012 S10boot -> ../init.d/boot
lrwxrwxrwx    1 root     root            14 Jun  8  2012 S11ubus -> ../init.d/ubus
lrwxrwxrwx    1 root     root            17 Jun  8  2012 S20network -> ../init.d/network

At what order Sxy would such a custom script be sufficient from your perspective? Between S11ubus and S20network? Just trying to get a second opinion before messing up wink

7x La Fonera 2100, 1x NanoStation2 Loco
running bleeding edge openwrt backfire/attitude adjustment
or4n9e on irc.freenode.net

2 (edited by eeff11 2013-06-14 04:28:54)

Re: macchanger upon boot

Hi, Orange,

Good to see you active again.

Any progress about AAP v4?

Now I have a tp-link wr840n v1, flashed with backfire 10.3.1 rc6.
In your post, you just listed the scripts but I found I'm using ath9k not madwifi for my wr840.And the macchanger ipk can't be installed in rc6.

So I'm finding ways to flash with it for madwifi or wating for you next version of AAP.

Re: macchanger upon boot

eeff1,

see my answer at https://forum.openwrt.org/viewtopic.php … 88#p204688

7x La Fonera 2100, 1x NanoStation2 Loco
running bleeding edge openwrt backfire/attitude adjustment
or4n9e on irc.freenode.net

Re: macchanger upon boot

hi, Organge,

Have you solved this problem? Anyone knows to help?

I have a tplink router that works in 'sta'mode, now I need it to randomly change it's wwan mac each boot for this router repeats a free city wifi that each mac has 12 hour connection limit.

While I installed the macchanger ipk in AA 12.09, put the "macchanger wlan0 -r" in the initial script, the wwan mac address stays the same, which is the original one.

Any one can help, I have searched a lot.Others have AP runing before sta, I only did it as a simple repeater, ''sta',

Any idea?

5 (edited by FriedZombie 2013-10-03 15:40:12)

Re: macchanger upon boot

anyway i wrote a script that changes the macaddress on boot before the wifi interface comes online, and each time the timeout runs out

#!/bin/sh /etc/rc.common

START=17

prefix='28:6A:BA' #prefix used for the mac address, randomizing this part gave strange errors (sometimes)
iface=0 #interface number according to: uci show wireless
renew=39600 #timeout to renew the mac address in secconds

pidfile="/var/run/macChanger.pid"

start() {
  if [ -f "${pidfile}" ]; then
    pid=`cat "${pidfile}"`
    if [ ! -z `top -bn1 | awk '{if ($1 == "'"${pid}"'") print $1}'` ]; then
      logger -t "mac changer" -s -p daemon.error "already running!"
      return  1
    fi
  fi
  logger -t "mac changer" -s -p daemon.info "started"
  while [ true ]; do
    mac="${prefix}"`hexdump -n3 -v -e '/1 ":%02X"' /dev/urandom`
    network=`uci get wireless.@wifi-iface[${iface}].network`
    if [ $? -ne 0 ]; then
      logger -t "mac changer" -s -p daemon.error "iface ${iface} not found, exiting"
      exit 1
    fi
    uci set wireless.@wifi-iface[${iface}].macaddr="${mac}"
    uci commit wireless
    logger -t "mac changer" -p daemon.info "new mac: ${mac} set for: ${network}"
    [ "$action" != "boot" ] && /sbin/wifi restart 2> /dev/null || action=''
    sleep "${renew}"
  done&
  echo $! > "${pidfile}"
}

stop() {
  if [ -f "${pidfile}" ]; then
    pid=`cat "${pidfile}"`
    rm "${pidfile}"
    if [ ! -z `top -bn1 | awk '{if ($1 == "'"${pid}"'") print $1}'` ]; then
      kill ${pid} $(top -bn1 | awk '{if ($2 == "'$pid'") print $1}')
      logger -t "mac changer" -s -p daemon.info "stopped"
      return 0
    fi
  fi
  logger -t "mac changer" -s -p daemon.error "not running!"
  return 1
}

save the file to /etc/init.d/macChanger
make it executable chmod +x /etc/init.d/macChanger
and enable it /etc/init.d/macChanger enable

Make sure that you save the file under unix type, (windows uses a slightly different line termination).
one way to do it under putty:
type cat > /etc/init.d/macChanger
paste the whole script and press [crtl]+d and the file is saved as well
(afterwards you can ofcourse edit it with vi on the router.

edit: removed small bug

Re: macchanger upon boot

yeah, FriedZombie,thank you so much.

I am exploring how to use the official macchanger.ipk correctly, I have already installed it. Wondering how to use it for each boot, so that I can connect to the free city wifi each day for 12 hours. Since there too many 'inside tricks' in openwrt, so still no sucess.

Your script seems to reinvent the wheel. But I will test it when I got another mini router.

7 (edited by FriedZombie 2013-10-04 12:43:18)

Re: macchanger upon boot

Good luck with the macchanger, the problem you will run into is the wifi manager, (wpa_supplicant) and some other things.
that's why I wrote this script. (I never got macchanger working properly, but if you only need it at boot before those things get started you have a good chance).

Also it are not really insider tricks, they are pretty well documented on the wiki.
Understanding how linux works goes a long way as well

if you want macchanger to run before the wifi comes online, i recommend to write a simple init script. Since the rc.local script runs after all the other scripts.

store into something like /etc/init.d/script

#!/bin/sh /etc/rc.common

START=17

start() {
  # your code here
}

and enable it with /etc/init.d/script enable

the network starts on 20 so your command will be executed before the network comes online
One more advantage I can think of in my script, is that you don't have to restart your router every 12 hours (call it lazy)

http://wiki.openwrt.org/doc/techref/initscripts
http://wiki.openwrt.org/doc/techref/process.boot