subprocess - Why can't I execute my python program with gksu? -


i have finished writing first python program gui. largely refined first program ever wrote, wifi capture program. whenever try run program pkexec or gksu, fails 'copy users xauthority file'.

i able program work adding sudo directly subprocess calls , making sure sudo -v first. had add shell = true popen tcpdump process. seems in case it's okay i'm using it, since there's no user input inject. suppose write script start program, that's sloppy.

any appreciated!

import subprocess import gi gi.require_version('gtk', '3.0') gi.repository import gtk datetime import datetime  channel = '1' width = '20' adapter = 'wlan0' dump = ''   class sniffer(object):     def __init__(self):         #build gui         self.builder = gtk.builder()         self.glade_file = 'sniff.glade'         self.builder.add_from_file(self.glade_file)          #get objects         go = self.builder.get_object         self.window = go('mainwindow')         self.myliststore1 = go('liststore1')         self.myliststore2 = go('liststore2')         self.combobox1 = go('channels')         self.combobox2 = go('widths')          # initialize interface         self.combobox1.set_active(0)         self.combobox2.set_active(0)          # connect signals         self.builder.connect_signals(self)          # go!         self.window.show()      def main_quit(self, *args):         gtk.main_quit()      def channel_change(self, widget, data=none):         model = widget.get_model()         active = widget.get_active()         code = model[active][0]         global channel         channel = code      def width_change(self, widget, data=none):         model = widget.get_model()         active = widget.get_active()         code = model[active][0]         global width         width = code      def on_press(self, button):         if button.get_active():             global adapter             adapter = find_adapter()             print adapter             start_monitor()             name_file()             do_capture()         else:             dump.terminate()             stop_capture()   def find_adapter():     adapter_output = subprocess.check_output(['iw', 'dev']).split()     x = adapter_output.index('interface')     adapter = adapter_output[x + 1]     return adapter   def start_monitor():     wifi_down = subprocess.check_output(         ['sudo', 'ip', 'link', 'set', 'dev', adapter, 'down'])     del_wifi = subprocess.check_output(['sudo', 'iw', 'dev', adapter, 'del'])     add_mon = subprocess.check_output([         'sudo', 'iw', 'phy', 'phy0', 'interface', 'add', 'mon0', 'type',         'monitor'     ])     mon_up = subprocess.check_output(         ['sudo', 'ip', 'link', 'set', 'dev', 'mon0', 'up'])     set_channel = subprocess.check_output(         ['sudo', 'iw', 'dev', 'mon0', 'set', 'channel', channel, width])     return   def stop_monitor():     mon_down = subprocess.check_output(         ['sudo', 'ip', 'link', 'set', 'dev', 'mon0', 'down'])     del_mon = subprocess.check_output(['sudo', 'iw', 'dev', 'mon0', 'del'])     add_wifi = subprocess.check_output([         'sudo', 'iw', 'phy', 'phy0', 'interface', 'add', adapter, 'type',         'managed'     ])     return   def name_file():     global file_name     file_name = str(datetime.now())[:-7].replace(         " ", "_") + "_ch{}".format(channel) + ".pcap"     return file_name   def do_capture():     global dump     dump = subprocess.popen(         ['sudo tcpdump -w {} -tvvv -s 0 -i mon0'.format(file_name)],         stdout=subprocess.pipe,         stderr=subprocess.pipe,         shell=true)   def stop_capture():     dump.terminate()     stop_monitor()   if __name__ == '__main__':     try:         gui = sniffer()         gtk.main()     except keyboardinterrupt:         pass 


Comments

Popular posts from this blog

node.js - Node js - Trying to send POST request, but it is not loading javascript content -

javascript - Replicate keyboard event with html button -

javascript - Web audio api 5.1 surround example not working in firefox -