Restart NetworkManager if killed, using 'service' command.

Previously only restarted network-manager if iface was put into monitor mode.

Also tries systemctrl if 'service' fails.

Should resolve #70
This commit is contained in:
derv82
2018-03-10 14:47:14 -05:00
parent 0a81774c59
commit 9661da51e0
4 changed files with 40 additions and 3 deletions

View File

@@ -394,7 +394,9 @@ if __name__ == '__main__':
while aireplay.is_running(): while aireplay.is_running():
from time import sleep from time import sleep
sleep(0.1) sleep(0.1)
print aireplay.get_output() stdout, stderr = aireplay.get_output()
print "STDOUT>", stdout
print "STDERR>", stderr
''' '''
''' '''

View File

@@ -13,6 +13,7 @@ import signal
class Airmon(object): class Airmon(object):
''' Wrapper around the 'airmon-ng' program ''' ''' Wrapper around the 'airmon-ng' program '''
base_interface = None base_interface = None
killed_network_manager = False
def __init__(self): def __init__(self):
self.refresh() self.refresh()
@@ -251,6 +252,8 @@ class Airmon(object):
Color.pl('{!} {R}terminating {O}conflicting process' + Color.pl('{!} {R}terminating {O}conflicting process' +
' {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)
if pname == 'NetworkManager':
Airmon.killed_network_manager= True
@staticmethod @staticmethod
def put_interface_up(iface): def put_interface_up(iface):
@@ -261,8 +264,36 @@ class Airmon(object):
@staticmethod @staticmethod
def start_network_manager(): def start_network_manager():
Color.p("{!} {O}restarting {R}NetworkManager{O}...") Color.p("{!} {O}restarting {R}NetworkManager{O}...")
(out,err) = Process.call('systemctl start NetworkManager')
Color.pl(" {R}restarted{W}") if Process.exists('service'):
cmd = 'service network-manager start'
proc = Process(cmd)
(out, err) = proc.get_output()
if proc.poll() != 0:
Color.pl(" {R}Error executing {O}%s{W}" % cmd)
if out is not None and out.strip() != "":
Color.pl(" {O}STDOUT> %s{W}" % out)
if err is not None and err.strip() != "":
Color.pl(" {O}STDERR> %s{W}" % err)
else:
Color.pl(" {GR}restarted{W} ({C}%s{W})" % cmd)
return
if Process.exists('systemctl'):
cmd = 'systemctl start NetworkManager'
proc = Process(cmd)
(out, err) = proc.get_output()
if proc.poll() != 0:
Color.pl(" {R}Error executing {O}%s{W}" % cmd)
if out is not None and out.strip() != "":
Color.pl(" {O}STDOUT> %s{W}" % out)
if err is not None and err.strip() != "":
Color.pl(" {O}STDERR> %s{W}" % err)
else:
Color.pl(" {GR}restarted{W} ({C}%s{W})" % cmd)
return
else:
Color.pl(" {R}can't restart NetworkManager: {O}systemctl{R} or {O}service{R} not found{W}")
if __name__ == '__main__': if __name__ == '__main__':
Airmon.terminate_conflicting_processes() Airmon.terminate_conflicting_processes()

View File

@@ -322,7 +322,10 @@ class Configuration(object):
if hasattr(Configuration, "interface") and Configuration.interface is not None and Airmon.base_interface is not None: if hasattr(Configuration, "interface") and Configuration.interface is not None and Airmon.base_interface is not None:
Airmon.stop(Configuration.interface) Airmon.stop(Configuration.interface)
Airmon.put_interface_up(Airmon.base_interface) Airmon.put_interface_up(Airmon.base_interface)
if Airmon.killed_network_manager:
Airmon.start_network_manager() Airmon.start_network_manager()
exit(code) exit(code)
@staticmethod @staticmethod

View File

@@ -114,6 +114,7 @@ class Process(object):
self.pid.wait() self.pid.wait()
if self.out is None: if self.out is None:
(self.out, self.err) = self.pid.communicate() (self.out, self.err) = self.pid.communicate()
return (self.out, self.err)
def poll(self): def poll(self):
''' Returns exit code if process is dead, otherwise "None" ''' ''' Returns exit code if process is dead, otherwise "None" '''