#!/usr/bin/perl -Tw # # Generate a random MAC address, and # and configure your card to use this new address. # # Useful for attempting to hide on networks where anyone can # get a dhcp lease, and in other situations. # # I by no means take responsibility for your misuse of this script, # or for that matter, dhcp. # # Consider nuking your client cache files too (/etc/dhcpc/ for me). # # jon use strict; use diagnostics; use Getopt::Long; $ENV{'PATH'} = "/usr/bin:/bin"; delete @ENV{qw(IFS CDPATH ENV BASH_ENV)}; GetOptions( "iface=s" => \(my $opt_iface)); my $interface; my $IFCONFIG = "/sbin/ifconfig"; my $DHCPCD = "/sbin/dhcpcd"; my $DHCPCD_OPTS = ""; $SIG{INT} = $SIG{QUIT} = \&reset; if ($opt_iface =~ /^([\w\d]+)$/ ) { $interface = $1; } else { die "Please provide a valid interface!\n"; } my $p1 = substr(unpack("H32", pack("N", int rand(32))), -2); my $p2 = substr(unpack("H32", pack("N", int rand(32))), -2); my $p3 = substr(unpack("H32", pack("N", int rand(32))), -2); my $p4 = substr(unpack("H32", pack("N", int rand(32))), -2); my $p5 = substr(unpack("H32", pack("N", int rand(32))), -2); my $p6 = substr(unpack("H32", pack("N", int rand(32))), -2); my $new_mac = $p1 . ":" . $p2 . ":" . $p3 . ":" . $p4 . ":" . $p5 . ":" . $p6; print("Taking $interface down...\n"); system("$IFCONFIG $interface down"); unless($?) { print("Changing MAC to $new_mac...\n"); system("$IFCONFIG $interface hw ether $new_mac"); unless($?) { print("Getting new address...\n"); system("$DHCPCD $DHCPCD_OPTS $interface"); unless($?) { print("Did it work?\n"); system("$IFCONFIG $interface"); } } } sub reset { print("Reset your interface!?"); }