/* * randmac.c v1.2 Final * I)ruid * * This little tool generates a random MAC address and sets the * specified interface to that MAC address (defaults to eth0 * if no interface is specified). * * You should not use this tool. Instead you should use macchanger, * as it has many more useful features: * * http://www.alobbs.com/modules.php?op=modload&name=macc&file=index * * Or, if you happen to use Windows, Technitium's tool is good: * * http://tmac.technitium.com/tmac/index.html * */ #include #include #include #include #define IFCONFIG "/sbin/ifconfig" int main( int argc, char *argv[] ) { int x, ret = 0; char *interface; char *command; char vendor[9]; int val[6]; /* Determine interface */ if( argc <= 1 ) { printf( "No interface specified, defaulting to eth0\n" ); interface = malloc( strlen("eth0")+1 ); sprintf( interface, "%s", "eth0"); } else { interface = argv[1]; printf( "Setting MAC for interface %s\n", interface ); } /* Seed rand() function */ sleep(1); srand(time(NULL)); /* Randomly Choose a Vendor */ switch( rand() % 10 ) { case 0: sprintf( vendor, "00:e0:f9" ); /* Cisco Systems */ break; case 1: sprintf( vendor, "00:00:d8" ); /* Novell */ break; case 2: sprintf( vendor, "00:00:36" ); /* Atari */ break; case 3: sprintf( vendor, "00:00:3D" ); /* Unisys */ break; case 4: sprintf( vendor, "00:00:75" ); /* Nortel Networks */ break; case 5: sprintf( vendor, "08:00:20" ); /* SUN Microsystems */ break; case 6: sprintf( vendor, "00:00:d9" ); /* Nippon Telegraph & Telephone */ break; case 7: sprintf( vendor, "00:03:93" ); /* Apple Computer */ break; case 8: sprintf( vendor, "10:00:5a" ); /* IBM */ break; case 9: sprintf( vendor, "00:d0:c6" ); /* Thomas & Betts */ break; default: sprintf( vendor, "08:00:07" ); /* Apple Computer */ break; } /* Choose Randomized Bits */ for( x = 0; x < 6; x++ ) { val[x] = rand() % 16; } /* Build command string */ command = malloc( strlen("IFCONFIG") + strlen(interface) + strlen(" hw ether ") + strlen(vendor) + 9 + 2 ); sprintf( command, "%s %s hw ether %s:%x%x:%x%x:%x%x\n", \ IFCONFIG, interface, vendor, \ val[0], val[1], val[2], val[3], val[4], val[5] ); /* Execute command */ printf( "Executing: %s", command ); ret = system(command); /* Exit with return value from command */ exit(ret); }