Skip to content

Instantly share code, notes, and snippets.

@thefinn93
Created February 16, 2012 21:22
Show Gist options
  • Save thefinn93/1847951 to your computer and use it in GitHub Desktop.
Save thefinn93/1847951 to your computer and use it in GitHub Desktop.
Sniff MAC addresses
#! /usr/bin/env python
from scapy.all import *
import sys
macs = set()
routerprefix = "00:24:6c"
try:
print "Importing from " + sys.argv[1]
savefile = open(sys.argv[1],"r")
for mac in savefile:
print mac
macs.add(mac)
print "Imported " + str(len(macs)) + " entries"
savefile.close()
except:
if len(sys.argv) > 1:
print sys.argv[1] + " not found. Creating new save file"
else:
print "Oops! You didn't specify a save file. please do so like this: "
print sys.argv[0] + " <filename>"
def hax(x):
try:
output = open(sys.argv[1],"a")
if x['RadioTap dummy'].addr1 not in macs:
if ":".join(x['RadioTap dummy'].addr1.split(":")[0:3]) != routerprefix:
print x['RadioTap dummy'].addr1
macs.add(x['RadioTap dummy'].addr1)
output.write(x['RadioTap dummy'].addr1 + "\n")
if x['RadioTap dummy'].addr2 not in macs:
if ":".join(x['RadioTap dummy'].addr2.split(":")[0:3]) != routerprefix:
print x['RadioTap dummy'].addr2
macs.add(x['RadioTap dummy'].addr2)
output.write(x['RadioTap dummy'].addr2 + "\n")
if x['RadioTap dummy'].addr3 not in macs:
if ":".join(x['RadioTap dummy'].addr3.split(":")[0:3]) != routerprefix:
print x['RadioTap dummy'].addr3
macs.add(x['RadioTap dummy'].addr3)
output.write(x['RadioTap dummy'].addr3 + "\n")
output.close()
except:
print "fuck!"
sniff(iface="mon0",prn=lambda x:hax(x))
#!/usr/bin/env python
from subprocess import call, Popen, PIPE
import random
import os
# This script changes the MAC address of iface to a random #
# one selected from the maclist file. It was originally #
# designed to combat potential monitoring by my University, #
# which requires that all MAC addresses connected to the wifi #
# be registered to a person. Unfortunately for them, it's quite #
# easy to switch MAC addresses. #
def changemac(maclist, iface):
DN = open(os.devnull, 'w') # /dev/null for sending shit
macs = open(maclist).read().split("\n") # Open the file and spilt by new line
newmac = macs[random.randint(0, len(macs)-1)] # pick a random MAC address
call(['ifconfig', iface, 'down']) # Take the interface down
proc = Popen(['ifconfig', iface, 'hw', 'ether', newmac], stdout=PIPE, stderr=DN)
proc.wait() # Change the MAC
call(['ifconfig', iface, 'up'], stdout=DN, stderr=DN) # Then bring the interface back up
return newmac # Return the new MAC address
if __name__ == "__main__":
print "Changed the MAC address to " + changemac("MACs.txt","wlan0")
Copy link

ghost commented Sep 5, 2012

Cactus

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment