This forum is in archive mode. You will not be able to post new content.

Author Topic: [py]mac generator/changer  (Read 711 times)

0 Members and 1 Guest are viewing this topic.

Offline kenjoe41

  • Symphorophiliac Programmer
  • Administrator
  • Baron
  • *
  • Posts: 990
  • Cookies: 224
    • View Profile
[py]mac generator/changer
« on: June 16, 2013, 02:57:56 PM »
Zyodox's idea of a mac changer. Its simple but it can get the work done.
Code: (python) [Select]
#!/usr/bin/python
#Simple Random Mac Generator Zy0d0x

import random
import argparse
import subprocess
import fcntl, socket, struct
import time

parser = argparse.ArgumentParser(
add_help=False, formatter_class=argparse.RawDescriptionHelpFormatter, epilog='Examples: %(prog)s -r -i wlan0')
parser.add_argument('-r', action='store_true', help='Set fully random MAC')
parser.add_argument('-v', action='store_true', help='Enable Verbose Mode')
parser.add_argument('-s', action='store_true', help='Print the MAC address and exit')
parser.add_argument('-i', dest='interface', help='Network Interface', required='yes')
parser.add_argument('-h', action='help', help='Print this help message and exit')

args = parser.parse_args()
interface = args.interface
randomized = args.r
show = args.s
verbose = args.v


def ifconfig_up(interface):
     if verbose == True:
            print 'Putting Interface %s Up' % interface
             subprocess.call(["ifconfig", interface, "up"])
       else:
        subprocess.call(["ifconfig", interface, "up"])

def ifconfig_down(interface):
    if verbose == True:
            print 'Putting Interface %s Down' % interface
            subprocess.call(["ifconfig", interface, "down"])
    else:
         subprocess.call(["ifconfig", interface, "down"])


if randomized == True and interface:
           
    def randomMAC():
        mac = [ random.randint(0x00, 0x00),
            random.randint(0x00, 0x2f),
            random.randint(0x00, 0x48),
            random.randint(0x00, 0xff),
            random.randint(0x00, 0xff),
            random.randint(0x00, 0xff) ]
        return ':'.join(map(lambda x: "%02x" % x, mac))
   
   
    newmac = randomMAC()
    ifconfig_down(interface)
    time.sleep(1)
    subprocess.Popen("ifconfig %s hw ether %s" %(interface,newmac), shell=True)
    time.sleep(1)
    ifconfig_up(interface)
    print 'Faked Mac:',newmac

   
if show  == True and interface:
   
    def getHwAddr(ifname):
            s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
            info = fcntl.ioctl(s.fileno(), 0x8927,  struct.pack('256s', ifname[:15]))
            return ''.join(['%02x:' % ord(char) for char in info[18:24]])[:-1]
       
    print getHwAddr(interface)
« Last Edit: June 16, 2013, 03:01:22 PM by kenjoe41 »
If you can't explain it to a 6 year old, you don't understand it yourself.
http://upload.alpha.evilzone.org/index.php?page=img&img=GwkGGneGR7Pl222zVGmNTjerkhkYNGtBuiYXkpyNv4ScOAWQu0-Y8[<NgGw/hsq]>EvbQrOrousk[/img]

Offline proxx

  • Avatarception
  • Global Moderator
  • Titan
  • *
  • Posts: 2803
  • Cookies: 256
  • ФФФ
    • View Profile
Re: [py]mac generator/changer
« Reply #1 on: June 16, 2013, 10:34:44 PM »
Nice piece of code, thanks for sharing.
Wtf where you thinking with that signature? - Phage.
This was another little experiment *evillaughter - Proxx.
Evilception... - Phage

 



Want to be here? Contact Ande, Factionwars or Kulverstukas on the forum or at IRC.