1
0
mirror of https://github.com/kmein/niveum synced 2026-03-16 18:21:07 +01:00

feat(scripts): new-mac

This commit is contained in:
2021-09-16 16:06:10 +02:00
parent 136b04cb3f
commit 0dc43c2eff
3 changed files with 23 additions and 0 deletions

View File

@@ -309,6 +309,12 @@ in rec {
packages = [ pkgs.curl pkgs.pup pkgs.gnused pkgs.gawk pkgs.gnugrep pkgs.fzf ];
};
new-mac = wrapScript {
script = ./new-mac.sh;
name = "new-mac";
packages = [ pkgs.gnused pkgs.openssl pkgs.jq pkgs.iproute2 ];
};
bvg = pkgs.callPackage ./bvg.nix { };
nav = pkgs.callPackage ./nav.nix { };
k-lock = pkgs.callPackage ./k-lock.nix { };

16
packages/scripts/new-mac.sh Executable file
View File

@@ -0,0 +1,16 @@
#!/bin/sh
random_mac() {
openssl rand -hex 6 | sed 's/\(..\)/\1:/g; s/.$//'
}
change_mac() {
old_mac="$(ip -j link show "$interface" | jq -r '.[].address')"
new_mac="$(random_mac)"
ip link set "$interface" address "$new_mac" 2>/dev/null && echo "$old_mac -> $new_mac"
}
interface="${1:-wlp3s0}"
ip link set "$interface" down
until change_mac; do :; done
ip link set "$interface" up