Wpa supplicant: Difference between revisions
imported>Rasmus-kirk m Fixed mac spoofing code |
imported>Rasmus-kirk Fixed mac spoofing |
||
| Line 47: | Line 47: | ||
Since there is no option to randomize your MAC address for wpa supplicant, you can instead create your own service using GNU's macchanger: | Since there is no option to randomize your MAC address for wpa supplicant, you can instead create your own service using GNU's macchanger: | ||
<syntaxHighlight lang=nix> | <syntaxHighlight lang=nix> | ||
systemd.services.macchanger = { | let | ||
change-mac = pkgs.writeShellScript "change-mac" '' | |||
card=$1 | |||
tmp=$(mktemp) | |||
${pkgs.macchanger}/bin/macchanger "$card" -s | grep -oP "[a-zA-Z0-9]{2}:[a-zA-Z0-9]{2}:[^ ]*" > "$tmp" | |||
mac1=$(cat "$tmp" | head -n 1) | |||
mac2=$(cat "$tmp" | tail -n 1) | |||
if [ "$mac1" = "$mac2" ]; then | |||
if [ "$(cat /sys/class/net/"$card"/operstate)" = "up" ]; then | |||
${pkgs.iproute2}/bin/ip link set "$card" down && | |||
macchanger -r "$card" | |||
${pkgs.iproute2}/bin/ip link set "$card" up | |||
else | |||
${pkgs.macchanger}/bin/macchanger -r "$card" | |||
fi | |||
fi | |||
''; | |||
in | |||
systemd.services.macchanger = { | |||
enable = true; | |||
description = "macchanger on wlan0"; | |||
wants = [ "network-pre.target" ]; | |||
before = [ "network-pre.target" ]; | |||
bindsTo = [ "sys-subsystem-net-devices-wlan0.device" ]; | |||
after = [ "sys-subsystem-net-devices-wlan0.device" ]; | |||
wantedBy = [ "multi-user.target" ]; | |||
serviceConfig = { | |||
Type = "oneshot"; | |||
ExecStart = "${change-mac} wlan0"; | |||
}; | |||
}; | }; | ||
</syntaxHighlight> | </syntaxHighlight> | ||
Where you need to change the <code> | Where you need to change the <code>wlan0</code> with your own wifi network interface. You can list your interfaces by running <code>ip link</code>, your wifi network interface should have "wl" prepended. Note that the above snippet fully randomizes your MAC address, for more information you can read macchanger's manpage. This obviously requires you to have the <code>macchanger</code> package installed. | ||
== External links == | == External links == | ||
[https://www.stura.htw-dresden.de/stura/ref/hopo/dk/nachrichten/eduroam-meets-nixos (german) article ''eduroam meets NixOS'' (with configuration)] (instance ''University of Applied Sciences Dresden'': The [https://cat.eduroam.org/?idp=5106&profile=5098 eduroam installer for GNU/Linux] works [https://www.htw-dresden.de/en/university/organisation/it-service-centre/services-for-workplace-and-communication/wi-fi-/-wlan/eduroam/linux for example for Ubuntu] but not [[NixOS]]) | [https://www.stura.htw-dresden.de/stura/ref/hopo/dk/nachrichten/eduroam-meets-nixos (german) article ''eduroam meets NixOS'' (with configuration)] (instance ''University of Applied Sciences Dresden'': The [https://cat.eduroam.org/?idp=5106&profile=5098 eduroam installer for GNU/Linux] works [https://www.htw-dresden.de/en/university/organisation/it-service-centre/services-for-workplace-and-communication/wi-fi-/-wlan/eduroam/linux for example for Ubuntu] but not [[NixOS]]) | ||