Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
derv82
GitHub Repository: derv82/wifite2
Path: blob/master/wifite/tools/macchanger.py
412 views
1
#!/usr/bin/env python
2
# -*- coding: utf-8 -*-
3
4
from .dependency import Dependency
5
from ..tools.ifconfig import Ifconfig
6
from ..util.color import Color
7
8
class Macchanger(Dependency):
9
dependency_required = False
10
dependency_name = 'macchanger'
11
dependency_url = 'apt-get install macchanger'
12
13
is_changed = False
14
15
@classmethod
16
def down_macch_up(cls, iface, options):
17
'''Put interface down, run macchanger with options, put interface up'''
18
from ..util.process import Process
19
20
Color.clear_entire_line()
21
Color.p('\r{+} {C}macchanger{W}: taking interface {C}%s{W} down...' % iface)
22
23
Ifconfig.down(iface)
24
25
Color.clear_entire_line()
26
Color.p('\r{+} {C}macchanger{W}: changing mac address of interface {C}%s{W}...' % iface)
27
28
command = ['macchanger']
29
command.extend(options)
30
command.append(iface)
31
macch = Process(command)
32
macch.wait()
33
if macch.poll() != 0:
34
Color.pl('\n{!} {R}macchanger{O}: error running {R}%s{O}' % ' '.join(command))
35
Color.pl('{!} {R}output: {O}%s, %s{W}' % (macch.stdout(), macch.stderr()))
36
return False
37
38
Color.clear_entire_line()
39
Color.p('\r{+} {C}macchanger{W}: bringing interface {C}%s{W} up...' % iface)
40
41
Ifconfig.up(iface)
42
43
return True
44
45
46
@classmethod
47
def get_interface(cls):
48
# Helper method to get interface from configuration
49
from ..config import Configuration
50
return Configuration.interface
51
52
53
@classmethod
54
def reset(cls):
55
iface = cls.get_interface()
56
Color.pl('\r{+} {C}macchanger{W}: resetting mac address on %s...' % iface)
57
# -p to reset to permanent MAC address
58
if cls.down_macch_up(iface, ['-p']):
59
new_mac = Ifconfig.get_mac(iface)
60
61
Color.clear_entire_line()
62
Color.pl('\r{+} {C}macchanger{W}: reset mac address back to {C}%s{W} on {C}%s{W}' % (new_mac, iface))
63
64
65
@classmethod
66
def random(cls):
67
from ..util.process import Process
68
if not Process.exists('macchanger'):
69
Color.pl('{!} {R}macchanger: {O}not installed')
70
return
71
72
iface = cls.get_interface()
73
Color.pl('\n{+} {C}macchanger{W}: changing mac address on {C}%s{W}' % iface)
74
75
# -r to use random MAC address
76
# -e to keep vendor bytes the same
77
if cls.down_macch_up(iface, ['-e']):
78
cls.is_changed = True
79
new_mac = Ifconfig.get_mac(iface)
80
81
Color.clear_entire_line()
82
Color.pl('\r{+} {C}macchanger{W}: changed mac address to {C}%s{W} on {C}%s{W}' % (new_mac, iface))
83
84
85
@classmethod
86
def reset_if_changed(cls):
87
if cls.is_changed:
88
cls.reset()
89
90
91