Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
derv82
GitHub Repository: derv82/wifite2
Path: blob/master/wifite/tools/ifconfig.py
412 views
1
#!/usr/bin/env python
2
# -*- coding: utf-8 -*-
3
4
import re
5
6
from .dependency import Dependency
7
8
class Ifconfig(Dependency):
9
dependency_required = True
10
dependency_name = 'ifconfig'
11
dependency_url = 'apt-get install net-tools'
12
13
@classmethod
14
def up(cls, interface, args=[]):
15
'''Put interface up'''
16
from ..util.process import Process
17
18
command = ['ifconfig', interface]
19
if type(args) is list:
20
command.extend(args)
21
elif type(args) is 'str':
22
command.append(args)
23
command.append('up')
24
25
pid = Process(command)
26
pid.wait()
27
if pid.poll() != 0:
28
raise Exception('Error putting interface %s up:\n%s\n%s' % (interface, pid.stdout(), pid.stderr()))
29
30
31
@classmethod
32
def down(cls, interface):
33
'''Put interface down'''
34
from ..util.process import Process
35
36
pid = Process(['ifconfig', interface, 'down'])
37
pid.wait()
38
if pid.poll() != 0:
39
raise Exception('Error putting interface %s down:\n%s\n%s' % (interface, pid.stdout(), pid.stderr()))
40
41
42
@classmethod
43
def get_mac(cls, interface):
44
from ..util.process import Process
45
46
output = Process(['ifconfig', interface]).stdout()
47
48
# Mac address separated by dashes
49
mac_dash_regex = ('[a-zA-Z0-9]{2}-' * 6)[:-1]
50
match = re.search(' ({})'.format(mac_dash_regex), output)
51
if match:
52
return match.group(1).replace('-', ':')
53
54
# Mac address separated by colons
55
mac_colon_regex = ('[a-zA-Z0-9]{2}:' * 6)[:-1]
56
match = re.search(' ({})'.format(mac_colon_regex), output)
57
if match:
58
return match.group(1)
59
60
raise Exception('Could not find the mac address for %s' % interface)
61
62
63