Created
May 17, 2010 03:27
-
-
Save fitorec/403364 to your computer and use it in GitHub Desktop.
Cambia a una Mac disponible apartir de una lista de MACs validas
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
#author: fitorec <http://fitorec.wordpress.com> | |
import os | |
import random | |
''' Parametros del script a configurar ''' | |
MAC_VALIDES = [ '00:21:00:89:49:4c', | |
'00:1f:5b:bb:01:36', | |
'00:13:02:61:4f:89', | |
'00:16:e3:6b:85:88' | |
] | |
INTERFACE = 'wlan0' | |
NET = '172.30.20.0' | |
system = lambda s : 'exec: '+s+"\n"+os.popen(s).read() | |
if system('id -un').find('root') < 0: | |
print 'Error: el script se debe de ejecutar como root' | |
exit(1) | |
MY_MAC = 'ifconfig '+INTERFACE+" | grep -o -E '([[:xdigit:]]{1,2}:){5}[[:xdigit:]]{1,2}'" | |
MY_MAC = os.popen(MY_MAC).read().replace("\n",'') | |
print 'MAC actual "'+MY_MAC+'"' | |
while MAC_VALIDES.count(MY_MAC) > 0: | |
MAC_VALIDES.remove(MY_MAC) | |
while MAC_VALIDES.count(MY_MAC.upper) > 0: | |
MAC_VALIDES.remove(MY_MAC.upper()) | |
print 'exec nmap -sP '+NET+'/24' | |
content = system('nmap -sP '+NET+'/24').upper() | |
print content | |
while len(MAC_VALIDES) > 0: | |
mac = MAC_VALIDES[random.randrange(len(MAC_VALIDES))] | |
if content.find(mac.upper())<0: | |
print "\n===================================" | |
print 'MAC['+mac+'] Disponible' | |
print system('ifconfig '+INTERFACE+' down') | |
print system('ifconfig '+INTERFACE+' hw ether '+mac) | |
print system('ifconfig '+INTERFACE+' up') | |
print 'Su MAC ha sido configurada exitosamente' | |
break | |
else: | |
print 'Direcion MAC: ['+mac+'] ocupada' | |
print 'Quedan '+str(len(MAC_VALIDES))+' MACs por probar' | |
MAC_VALIDES.remove(mac) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment