Giter Site home page Giter Site logo

semocode's Introduction

semocode

Author- semo

Simple python Script to change mac address of linux generate random or enter mac address

import random from subprocess import PIPE, Popen

function for returning terminal command

def cret(command): process = Popen(args=command, stdout=PIPE, shell=True) return process.communicate()[0]

function for genrate mac address random

def randmac(): return [ 0x00, 0x16, 0x3E, random.randint(0x00, 0x7F), random.randint(0x00, 0xFF), random.randint(0x00, 0xFF), ]

def retrandmac(mac): return ":".join(map(lambda x: "%02x" % x, mac))

print(" +-+-+-+ +-+-+-+-+-+-+-+") print(" |M|A|C| |c|h|a|n|g|e|r|") print(" +-+-+-+ +-+-+-+-+-+-+-+")

finding wireless interface name that should start with wl e.g.-wlan0,wlp3s0

infname = cret('ifconfig -a | egrep "^[wl-wl]+" | sed "s/: .*//" | grep -v "lo"')

INTERFACE NAME 6 character so return 6 last character

infname = infname[:6] infname = infname.decode("utf-8")

GETTING MAC Address from /sys/class/net/wlan0/address directory

cmdgetmac = "cat /sys/class/net/" + infname + "/address" crrntmac = cret("cat /sys/class/net/" + infname + "/address") crrntmac = crrntmac.decode("utf-8") print( "Your Current mac address = " + crrntmac + "\nEnter Option to change Your MAC:\n1. Enter MAC address manually \n2. Automatic Random MAC address" ) opt = int(input())

if opt == 1: print("Please Enter Your New MAC address: \nExmple: 46:d2:f4:0c:2a:50")

newmac = input()
print("Please wait changing  mac address..................")

# first turn off wifi
cret("nmcli radio wifi off")

changemaccmd = "sudo ip link set dev " + infname + " address " + newmac
# executing command with new mac address
cret(changemaccmd)
# turning on wifi
cret("nmcli radio wifi on")
# GETTING MAC Address from /sys/class/net/wlan0/address directory
cr = cret("cat /sys/class/net/" + infname + "/address")
cr = cr.decode("utf-8")

print("\nNow Your Current mac address = " + cr)

semocode's People

Contributors

semo789 avatar

Stargazers

zkabdu avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.