So I have this python script that I've written to randomly generate the host portion of mac address. The range of addresses is 00:00:00 - 7F:FF:FF, which is about 8,388,608 possibilities. So what this is supposed to do is write each mac to a file, and then check said file for duplicates. However this isn't happening, even on one iteration, and still not happening when I run 565 iterations. Here's the code:
#!/usr/bin/pythonimport randomimport osdef randomMAC(): mac = [ 0x54, 0x52, 0x00, random.randint(0x00, 0x7f), random.randint(0x00, 0xff), random.randint(0x00, 0xff) ] return ':' .join(map(lambda x: "%02x" % x, mac))def writeMAC(randomMAC): f = open('macaddresses.txt','w') for k in range(1,566): #s = str(randomMAC()) #f.write(s) print >>f, randomMAC() f.close()def Iteration(writeMAC): for i in range(1,8388608): writeMAC(randomMAC) os.system('echo "Iteration "' + str(i) + '>> duplicatereport.txt && cat macaddresses.txt | uniq -cd >> duplicatereport.txt 2>&1') os.remove('macaddresses.txt')#for k in range(565, 0, -1):# for i in range(8388607, 0, -1):# print randomMAC()#f = open('holler.txt','w')#for i in range(8388607, 0, -1):# print >>f, randomMAC()#f.close()#os.system('echo "ITERATION 1" && cat holler.txt | uniq -cd > duplicatereport.txt 2>&1')#os.remove('holler.txt')#for i in range(1,6):# os.system('echo "Iteration "' + str(i) + '>> duplicatereport.txt && cat macaddresses.txt | uniq -cd >> duplicatereport.txt 2>&1')Iteration(writeMAC)
1/11/2011 1:44:10 PM
By my math, you need a set of approximately 3600 before you can expect a collision.
1/11/2011 2:10:01 PM
Yeah I'm thinking there should be duplicates occurring at a higher frequency than what my script is producing.
1/11/2011 2:18:22 PM
It looks like a limitation in the "uniq" command.I generated a file with 4 million MAC addresses, changed the last 2 to be the same, and it found just them.I then changed maybe the 20th MAC address down in the list, and it did not pick it up as a duplicate.Looks like you're writing your own duplicate-finding function...[Edited on January 11, 2011 at 2:43 PM. Reason : ]
1/11/2011 2:43:46 PM
shit, I was hoping that wouldn't be the case. Well, time to pound out some code.
1/11/2011 5:17:34 PM
uniq requires the input to be sorted
1/11/2011 6:29:26 PM
just pipe it though sort before uniqfrom the manpage:
1/11/2011 8:39:11 PM
yeah, I'm piping it through sort at the moment, and its finding lots of collisions/duplicates. thanks for the heads up tdub!
1/13/2011 10:31:44 AM