Results 1 to 4 of 4

Thread: Perl script to randomize MAC address

Hybrid View

  1. #1
    Just burned his ISO
    Join Date
    Mar 2011
    Posts
    4

    Default Perl script to randomize MAC address

    I wrote this quick&dirty Perl script to randomize MAC address. Tested on BT4R2, works fine.

    Code:
    #!/usr/bin/perl
    
    # MAC ADDRESS RANDOMIZER
    # by m0skit0 (acidkaos@hotmail.com)
    # 16/03/2011
    
    use strict;
    
    # GLOBALS
    my $device;
    
    sub check_args()
    {
    	if ($#ARGV != 0)
    	{
    		print "Usage: perl mac_addr_randomize <device>\n";
    		exit;
    	}
    
    	$device = $ARGV[0];
    }
    
    sub generate_random_mac()
    {
    	my $mac = "";	
    	for(my $i = 0; $i < 6; $i++)
    	{
    		$mac = $mac.sprintf("%02x", int(rand(256))).":";
    	}	
    	chop($mac);
    	return $mac;
    }
    
    sub main()
    {
    	check_args();
    	my $new_mac = generate_random_mac();
    	print $new_mac."\n";
    	system("ifconfig", $device, "down");
    	system("macchanger", "-m", $new_mac, $device);
    	system("ifconfig", $device, "up");
    	return;
    }
    
    main();
    The script automates ifconfig down and up process, but you can comment this lines if you want to do it manually.

    PS: if you're on a DHCP network, you'll need to send a new DHCPREQUEST to fill the kernel routing table.

    PS: I'm still learning Perl, so be kind xD

    PS: please if this does not fit here, my apologies!

  2. #2
    Junior Member leg3nd's Avatar
    Join Date
    Feb 2011
    Posts
    32

    Default Re: Perl script to randomize MAC address

    Sorry maybe im missing something, besides ifup/ifdown, doesn't 'macchanger -r' set a fully random MAC and 'macchanger -A' sets a random hardware vendor MAC. Might be more elegant to throw a 4 line bash script together.

    Either way nice bit of code, i just try not to reinvent the wheel

  3. #3
    Senior Member
    Join Date
    May 2010
    Posts
    198

    Default Re: Perl script to randomize MAC address

    This is a pretty creative way to do it though. Thanks for sharing.

    @leg3nd I agree - My logon script looks like something like this

    Code:
    interface="wlan0"  #or whatever
    mac_temp=/tmp/tmp
    ifconfig $interface down
    /usr/bin/notify-send "Randomly Spoofing MAC Address"
    macchanger -r $interface > $mac_temp
    mac="$(cat $mac_temp)"
    /usr/bin/notify-send "$mac"
    ifconfig $interface up
    Quote Originally Posted by leg3nd View Post
    Sorry maybe im missing something, besides ifup/ifdown, doesn't 'macchanger -r' set a fully random MAC and 'macchanger -A' sets a random hardware vendor MAC. Might be more elegant to throw a 4 line bash script together.

    Either way nice bit of code, i just try not to reinvent the wheel
    Last edited by Scamentology; 03-19-2011 at 10:21 PM.
    "Never do anything against conscience -- even if the state demands it."
    -- Albert Einstein

  4. #4
    Just burned his ISO
    Join Date
    Mar 2011
    Posts
    4

    Default Re: Perl script to randomize MAC address

    @leg3nd: you're totally right, i didnt know macchanger had such option (which is obvious now that you mention it ).

    Anyway just sharing it, it's useful for practicing Perl

Similar Threads

  1. packetstorm exploit archive grabber [PERL script]
    By fnord0 in forum Experts Forum
    Replies: 0
    Last Post: 02-21-2011, 06:39 AM
  2. Another WEP crack script with GUI written in perl
    By fastzones in forum Beginners Forum
    Replies: 8
    Last Post: 09-04-2010, 06:17 AM
  3. OUI (MAC address) lookup script
    By Hawkje in forum Experts Forum
    Replies: 11
    Last Post: 07-12-2010, 08:18 PM
  4. psw gen perl script to work with hydra or mudusa ?
    By qam47 in forum OLD BT3beta Software related issues
    Replies: 2
    Last Post: 03-09-2008, 07:34 PM
  5. Word maniplulator (perl script)
    By SyntaxErr0r in forum OLD Programming
    Replies: 0
    Last Post: 10-04-2007, 05:30 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •