Put interfaces up and start Network Manager after exit

This commit is contained in:
Vinicius Henrique Marangoni
2016-12-28 13:41:31 -02:00
parent 5be2ea32f9
commit d3b966d8d8
3 changed files with 18 additions and 3 deletions

View File

@@ -250,6 +250,17 @@ class Airmon(object):
' {R}%s{O} (PID {R}%s{O})' % (pname, pid)) ' {R}%s{O} (PID {R}%s{O})' % (pname, pid))
os.kill(int(pid), signal.SIGTERM) os.kill(int(pid), signal.SIGTERM)
@staticmethod
def put_interfaces_up():
Color.pl("{+} {O}Putting interfaces up...")
for interface in Airmon.get_interfaces():
Color.pl("{+} {B}up into {O}%s" %(interface.name))
(out,err) = Process.call('ifconfig %s up' %(interface.name))
@staticmethod
def start_network_manager():
Color.pl("{+} {O}Starting NetworkManager")
(out,err) = Process.call('systemctl start NetworkManager')
if __name__ == '__main__': if __name__ == '__main__':
Airmon.terminate_conflicting_processes() Airmon.terminate_conflicting_processes()

View File

@@ -276,6 +276,10 @@ class Configuration(object):
def exit_gracefully(code=0): def exit_gracefully(code=0):
''' Deletes temp and exist with the given code ''' ''' Deletes temp and exist with the given code '''
Configuration.delete_temp() Configuration.delete_temp()
from Airmon import Airmon
Airmon.stop(Configuration.interface)
Airmon.put_interfaces_up()
Airmon.start_network_manager()
exit(code) exit(code)
@staticmethod @staticmethod
@@ -300,4 +304,3 @@ class Configuration(object):
if __name__ == '__main__': if __name__ == '__main__':
Configuration.initialize(False) Configuration.initialize(False)
print Configuration.dump() print Configuration.dump()

View File

@@ -91,6 +91,8 @@ class Interface(object):
output = Process(['ifconfig', iface]).stdout() output = Process(['ifconfig', iface]).stdout()
mac_regex = ('[a-zA-Z0-9]{2}-' * 6)[:-1] mac_regex = ('[a-zA-Z0-9]{2}-' * 6)[:-1]
match = re.search('HWaddr (%s)' % mac_regex, output) match = re.search('HWaddr (%s)' % mac_regex, output)
if not match:
match = re.search('unspec (%s)' % mac_regex, output)
if not match: if not match:
raise Exception('Could not find the mac address for %s' % iface) raise Exception('Could not find the mac address for %s' % iface)
return match.groups()[0].replace('-', ':') return match.groups()[0].replace('-', ':')
@@ -98,4 +100,3 @@ class Interface(object):
if __name__ == '__main__': if __name__ == '__main__':
mac = Interface.get_mac() mac = Interface.get_mac()
print 'wlan0mon mac address:', mac print 'wlan0mon mac address:', mac