Re: macchanger - is it still working?
Good Day Everyone,
Am Montag, 9. Mai 2022 schrieb Hans:
> IFACE = --all
> /usr/bin/macchanger: unrecognized option '--all'
> GNU MAC Changer
Yes. The problem is that the script /etc/macchanger/ifupdown.sh which is
shipped with the macchanger package processes $IFACE without checking
its value.
package=macchanger
/usr/bin/${package} -e $IFACE >> $LOGFILE 2>&1
When $IFACE == "--all" which is a valid option for ifup as David pointed
out then macchanger fails and reports the above error message to its
logfile because macchanger understands "--all" as on option which it
doesn't know.
Am Montag, 9. Mai 2022 schrieb David Wright:
> A workaround for your problem might be to set IFACE appropriately
> in /etc/default/macchanger.
A solution I found is to change the script /etc/macchanger/ifupdown.sh
so that it checks for the value of $IFACE against the value of
$ENABLE_INTERFACES (sourced from /etc/default/macchanger) and only then
processes that accordingly. $ENABLE_INTERFACES on my system contains
only "net0" so all is fine here.
A version of this script which works on my system (Devuan Beowulf) is
attached.
Another approach I haven't tested yet could be to add "--" to the line
which invokes maccanger so that the value of "$IFACE" being "--all"
wouldn't be treated as an option but as an argument and given to ifup
or whatever macchanger internally uses to actually change the MAC. But
I don't know if macchanger understands "--".
/usr/bin/$package -a -- "$IFACE" >> $LOGFILE 2>&1
HTH
Kind regards,
Stefan
#!/bin/sh
# $Id: ifupdown.sh,v 2.0 2021-04-21 16:23:42+02 stekru Exp $
# randomize MAC address before connecting to wifi or ethernet
#
# This script should always be run in if-pre-up.d, but unfortunately
# NetworkManager does not run if-pre-up.d scripts before it sets up a network
# connection (https://bugzilla.gnome.org/show_bug.cgi?id=387832).
# if-post-down.d scripts are run, so there is a symlink to this script
# there. That means when running network config from the terminal, macchanger
# will be run twice, but it'll only be run in if-post-down.d when using
# NetworkManager.
package=macchanger
LOGFILE=/var/log/$package.log
#LOGFILE=~/.local/log/$package.log
echo >> $LOGFILE
date '+%Y-%m-%d %T' >> $LOGFILE
# Vorgaben einlesen; hier wird auch ENABLE_INTERFACES="net0" eingelesen.
if [ -f /etc/default/$package ]; then
. /etc/default/$package
else
echo "Config file /etc/default/$package not found" >> $LOGFILE
exit 1
fi
if [ "$ENABLE_ON_POST_UP_DOWN" != "true" ]; then
echo "Macchanger is disabled in /etc/default/$package" >> $LOGFILE
exit
fi
# Where comes '$IFACE' from? From networking or ifup/-down/-query?
# The variable could be read from the environment. Where (from which
# program) would it be exported. No arguemnts are being processed here.
echo "Processing: IFACE = $IFACE" >> $LOGFILE
if [ -z "$ENABLE_INTERFACES" ]; then
echo "No interface enabled in /etc/default/$package" >> $LOGFILE
exit 0
else
case "$IFACE" in
*$ENABLE_INTERFACES*)
/usr/bin/$package -a "$IFACE" >> $LOGFILE 2>&1
;;
*)
echo "Ignoring not configured interface: $IFACE" >> $LOGFILE
exit 0
;;
esac
fi
Reply to: