Repository navigation
Expand file tree
/
Copy pathLinuxMacChanger.py
More file actions
71 lines (56 loc) · 2.31 KB
/
Copy pathLinuxMacChanger.py
File metadata and controls
71 lines (56 loc) · 2.31 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
'''
Require command for mac changer
Current Mac:40:8d:5c:d8:8c:92
**********************************
ifconfig [interface] down
ifconfig [interface] hw ether [mac_address]
ifconfig [interface] up
**************************************'''
import subprocess as sp
from optparse import OptionParser
import re
def changeMac(interface,mac):
if interface==None or mac==None:
print('[!] Please give input for Interface and Mac Address')
elif(isThisMac(mac)):
cm=getCurrentMac(interface)
print(f'[*] Your current Mac address:{cm}')
print(f'[+] Start Changing mac address of interface {interface} into {mac}')
print("**************************************************************************************")
sp.call(f'sudo ifconfig {interface} down',shell=True)
try:
sp.call(f'sudo ifconfig {interface} hw ether {mac}',shell=True)
except :
pass
sp.call(f'sudo ifconfig {interface} up',shell=True)
nm=getCurrentMac(interface)
if cm==nm:
print(f"[!] Process failed \n[*] your current mac is {cm}")
else:
print(f"[+] Your mac has been change successfully.\n[*] Your Current Mac Address: {nm}")
else:
print(f'[!] You are a stupid, {mac} is not a valid mac address' )
def isThisMac(mac):
flag=True
if len(mac)!=17:
return False
else:
for i in range(0,len(mac)):
if (i+1)%3==0 and (mac[i]!=':'):
flag=False
return flag
def getCurrentMac(interface):
output=sp.check_output(f'ifconfig {interface}',shell=True)
output=str(output)
list_of_mac=re.search(r"\w\w:\w\w:\w\w:\w\w:\w\w:\w\w",output)
return list_of_mac.group(0)
if __name__ == "__main__":
# *******************************start Taking input********************************************************
parser=OptionParser()
parser.add_option("-i","--interface",dest="interface",help="Name of the interface to change it's MAC address")
parser.add_option("-m","--mac",dest="new_mac",help="Enter New Mac Address")
(options,argument)=parser.parse_args()
mac=options.new_mac
interface=options.interface
# **********************************END**********************************************************
changeMac(interface,mac)