raiden All American 10505 Posts user info edit post |
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/python
import random import os
def 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)
I know I'm missing something, b/c statistically speaking, I should be getting some duplicates, due to the birthday paradox.
Any thoughts/suggestions?1/11/2011 1:44:10 PM |
moron All American 34190 Posts user info edit post |
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 |