示例#1
0
    def __init__(self,
                 activeImage,
                 selectedImage,
                 offset=(0, 0),
                 size=(200, 200),
                 initialState=(0, 0),
                 wlan='192.168.1.3',
                 dT=1,
                 pings=[
                     '192.168.1.1', '192.168.1.2', '192.168.1.3',
                     '192.168.1.4', '192.168.1.5', '192.168.1.105',
                     '192.168.1.102', '192.168.1.103'
                 ]):
        StateManager.__init__(self, activeImage, selectedImage, offset, size,
                              initialState)
        self.wlan = wlan
        self.wlan1 = meter.SignalMeter(wlan, 1, dT)
        self.wlan1.start()
        self.wlan2 = meter.SignalMeter(wlan, 2, dT)
        self.wlan2.start()
        pygame.font.init()
        self.pingers = []
        for ping in pings:
            tmp = pinger.Pinger(ping, dT=3)
            tmp.start()
            self.pingers.append(tmp)
            self.ips[ping] = self.pingers[-1]

        self.myfont = pygame.font.SysFont("Arial", 18)
        self.myfont2 = pygame.font.SysFont("Courier", 10)
示例#2
0
    def start(self):
        pingur = threading.Thread(target=pinger.Pinger().timer,args=(self.sharedFile,0))
        pingur.daemon=True
        pingur.start()

        
        g = threading.Thread(target=gui.GUI().p,args=(self.sharedFile,))
        g.daemon=True
        g.start()

        status = threading.Thread(target=self.status_print)
        status.daemon=True
        status.start()
示例#3
0
    def getData(self):
        """
        Called by Directive docheck() method to fetch the data required for
        evaluating the directive rule.

        Ping a host a set number of times and record number of successful
        responses and round-trip-time stats (min/max and average).
        """
        data = {}

        # Perform the pinging
        try:
            p = pinger.Pinger(self.args.host, self.args.numpings)
        except socket.error, err:
            log.log(
                "<ping>PING.getData(): Socket Error, host '%s', %s" %
                (self.args.host, err), 5)
            data['alive'] = 0
            return data
示例#4
0
def get_pinger():
    with app.app_context():
        thepinger = getattr(g, '_pinger', None)
        if thepinger is None:
            thepinger = pinger.Pinger(thefinder, pianod)
        return thepinger
示例#5
0
    def __init__(self):
        self.stop = False
        self.session_start = None
        self.last_traffic_in, self.last_traffic_out = None, None
        self.online = False
        self.timeout_changed = False
        self.versionChecked = False
        self.logTraffic = False
        self.discMsgDialog = False
        self.last_update = None

        self.pinger = pinger.Pinger("google.com", self.rtt_callback)

        ## db update
        self.db_update_interval = 20  # sec
        self.last_db_update = datetime.datetime.now()
        self.d_rb_db = self.d_tb_db = 0

        self.sys_info = ntmtools.getSysInfo()

        #print(self.sys_info)

        self.d_rb, self.d_tb = 0, 0

        self.home_path = os.getenv("HOME")
        self.profile_path = self.home_path + "/" + globaldef.NTM_PROFILE_RELPATH

        if not os.path.exists(self.profile_path):
            os.makedirs(self.profile_path)

        db_file_path = self.profile_path + "/" + globaldef.NTM_DB_NAME
        self.db_conn = sqlite3.connect(db_file_path, check_same_thread=False)

        self.update_event = Event()

        ## Create tables
        self.create_tables(self.db_conn)

        res = ntmtools.read_db_var(self.db_conn, "general.interface")
        if res != None:
            self.interface = res
        else:
            ntmtools.dbg_msg(
                _("Wrong value for the param") + " 'general.interface' " +
                _("or is not stored. Default value") + " 'ttyACM0'.")
            ntmtools.set_db_var(self.db_conn, "general.interface", "ttyACM0")
            self.interface = "ttyACM0"

        self.interfaceProcNetDev = self.interface

        res = ntmtools.read_db_var(self.db_conn,
                                   "general.update_interval")  # sec
        try:
            self.update_interval = int(float(res))
        except:
            ntmtools.dbg_msg(
                _("Wrong value for the param") +
                " 'general.update_interval' " +
                _("or is not stored. Default value") + " '2'.")
            ntmtools.set_db_var(self.db_conn, "general.update_interval", "2")
            self.update_interval = 2

        res = ntmtools.read_db_var(self.db_conn,
                                   "general.last_version_check")  # datetime
        try:
            self.last_version_check = int(float(res))
            self.versionChecked = ((time.time() - self.last_version_check) <
                                   (5 * 24 * 60 * 60))
        except:
            ntmtools.dbg_msg(
                _("Wrong value for the param") +
                " 'general.last_version_check' " +
                _("or is not stored. Default value") + " '" + _("now") + "'.")
            ntmtools.set_db_var(self.db_conn, "general.last_version_check",
                                str(int(time.time())))
            self.last_version_check = int(time.time())
            self.versionChecked = False

        res = ntmtools.read_db_var(self.db_conn,
                                   "general.keep_above")  # 0 or 1
        try:
            self.ntmMainWindow_keep_above = (int(float(res)) != 0)
        except:
            ntmtools.dbg_msg(
                _("Wrong value for the param") + " 'general.keep_above' " +
                _("or is not stored. Default value") + " '0.")
            ntmtools.set_db_var(self.db_conn, "general.keep_above", "0")
            self.ntmMainWindow_keep_above = False

        res = ntmtools.read_db_var(self.db_conn, "general.opacity")  # 0 to 100
        try:
            self.ntmMainWindow_opacity = int(float(res))
        except:
            ntmtools.dbg_msg(
                _("Wrong value for the param") + " 'general.opacity' " +
                _("or is not stored. Default value") + " '100.")
            ntmtools.set_db_var(self.db_conn, "general.opacity", "100")
            self.ntmMainWindow_opacity = 100

        res = ntmtools.read_db_var(self.db_conn, "general.autorun")  # 0 or 1
        try:
            self.general_pref_autorun = (int(float(res)) != 0)
        except:
            ntmtools.dbg_msg(
                _("Wrong value for the param") + " 'general.autorun' " +
                _("or is not stored. Default value") + " '" + _("True") + "'.")
            ntmtools.set_db_var(self.db_conn, "general.autorun", "1")
            self.general_pref_autorun = True
        self.set_autorun(self.general_pref_autorun)

        res = ntmtools.read_db_var(
            self.db_conn, "general.online_check")  # 0->NetworkManager; 1->Ping
        try:
            self.general_pref_online_check = int(float(res))
        except:
            ntmtools.dbg_msg(
                _("Wrong value for the param") + " 'general.online_check' " +
                _("or is not stored. Default value") + " 0 (NetworkManager).")
            self.general_pref_online_check = 0
            ntmtools.set_db_var(self.db_conn, "general.online_check", "0")

        res = ntmtools.read_db_var(self.db_conn, "general.tray_activate_action"
                                   )  # 0->Show Main Window; 1->Show Nptify;
        try:
            self.general_pref_tray_activate_action = int(float(res))
        except:
            ntmtools.dbg_msg(
                _("Wrong value for the param") +
                " 'general.tray_activate_action' " +
                _("or is not stored. Default value") +
                " 0 (Show Main Window).")
            self.general_pref_tray_activate_action = 0
            ntmtools.set_db_var(self.db_conn, "general.tray_activate_action",
                                "0")

        res = ntmtools.read_db_var(self.db_conn, "general.trayicon_file")
        if res != None:
            ntmtools.dbg_msg("general.trayicon_file : " + res)
            self.trayicon_file = res
        else:
            ntmtools.dbg_msg(
                _("Wrong value for the param") + " 'general.trayicon_file' " +
                _("or is not stored. Default value") + " " +
                globaldef.DEFAULT_NTM_ICON_OFF)
            ntmtools.set_db_var(self.db_conn, "general.trayicon_file",
                                globaldef.DEFAULT_NTM_ICON_OFF)
            self.trayicon_file = globaldef.DEFAULT_NTM_ICON_OFF

        res = ntmtools.read_db_var(self.db_conn,
                                   "general.trayicon_active_file")
        if res != None:
            ntmtools.dbg_msg("general.trayicon_active_file : " + res)
            self.trayicon_active_file = res
        else:
            ntmtools.dbg_msg(
                _("Wrong value for the param") +
                " 'general.trayicon_active_file' " +
                _("or is not stored. Default value") + " " +
                globaldef.DEFAULT_NTM_ICON_ON)
            ntmtools.set_db_var(self.db_conn, "general.trayicon_active_file",
                                globaldef.DEFAULT_NTM_ICON_ON)
            self.trayicon_active_file = globaldef.DEFAULT_NTM_ICON_ON

        res = ntmtools.read_db_var(self.db_conn, "general.importexport_file")
        if res != None:
            self.importexport_file = res
        else:
            ntmtools.dbg_msg(
                _("Wrong value for the param") +
                " 'general.importexport_file' " +
                _("or is not stored. Default value") + " ''.")
            ntmtools.set_db_var(self.db_conn, "general.importexport_file", "")
            self.importexport_file = ""

        # NetMan
        self.net_man = netman.NetMan(self.general_pref_online_check,
                                     self.interface)
        self.net_man.add_online_handler(self.set_online)
        self.net_man.add_offline_handler(self.set_offline)

        # GUI
        self.ntmgui = ntmgui.NtmGui(self)

        self.ntmgui.apply_prop(self.ntmMainWindow_keep_above,
                               self.ntmMainWindow_opacity)
        self.set_autorun(self.general_pref_autorun)

        self.ntmgui.set_general_preferences(
            self.interface, self.update_interval,
            self.ntmMainWindow_keep_above, self.ntmMainWindow_opacity,
            self.general_pref_autorun, self.general_pref_online_check,
            self.general_pref_tray_activate_action, self.importexport_file)
        self.update_event += self.ntmgui.update_h

        self.session_start = datetime.datetime.now()

        self.info_win_load = True
        if self.net_man.get_state():
            ntmtools.dbg_msg("State : Online")
            self.set_online()
        else:
            ntmtools.dbg_msg("State : Offline")
            self.set_offline()

        # Traffic Module
        self.mtraffic = MTraffic.make_from_db(self)
        self.update_event += self.mtraffic.update_h
        self.ntmgui.set_traffic_module(self.mtraffic)

        # Time Slot Module
        self.mtimeslot = MTimeSlot.make_from_db(self)
        self.update_event += self.mtimeslot.update_h
        self.ntmgui.set_timeslot_module(self.mtimeslot)

        # Time Module
        self.mtime = MTime.make_from_db(self)
        self.update_event += self.mtime.update_h
        self.ntmgui.set_time_module(self.mtime)

        # Info/News
        self.info_win = ntminfo.NtmInfo(self.net_man.get_state())
        self.info_win_load = False

        gobject.timeout_add(self.update_interval * 1000, self.update_count)
        self.update_count(True)

        self.pinger.start()
示例#6
0
    if rc != 0:
        print("Failed to start P2P instance. Stopping test")
        p2p.DaemonRunning = False
        daemon.kill()

started = time.asctime(time.localtime(time.time()))

time.sleep(5)
p2p.CheckP2P(b.getHash(), hosts)

print("\nWaiting 60 seconds\n\n")
#Wait 60 seconds while containers status become READY
time.sleep(60)

print("Start to pinging\n")
p = pinger.Pinger()
for i in hosts:
    r = result.Result(i)
    p.setResult(r)
    p.setIP(i)
    bb = p.run()
    if bb == True:
        print("PING for", i, "is done")

    print("\nRESULTS of", i, ":\n")
    p.r.produce()
    print('\n')

destroyInProgress = False
print("Destroying environment.")
rc = b.destroy(envName)