Exemplo n.º 1
0
def check_network_status():
    print('check_network_status')

    ip = CLI.get_ip()
    if ip is None:
        CLI.start_accesspoint_mode()
        time.sleep(60)
Exemplo n.º 2
0
    def __handle(self, connection, address):
        import logging
        logging.basicConfig(level=logging.DEBUG)
        logger = logging.getLogger("process-%r" % (address, ))
        try:
            logger.debug("Connected %r at %r", connection, address)
            while True:
                if CLI.get_wifi_mode() == "Master":
                    ssid = CLI.get_ap_name()
                    mac = CLI.get_mac_address()
                    str = "{mode:\"AP\", ssid=\"" + ssid + "\", mac: \"" + mac + "\"}"
                    connection.sendall(str)
                elif CLI.get_wifi_mode() == "Managed":
                    ip = CLI.get_ip()
                    netmask = CLI.get_netmask()
                    gateway = CLI.get_gateway('wlan0')
                    ssid = CLI.get_connected_ssid_name()

                    if ip is None:
                        ip = ""

                    if netmask is None:
                        netmask = ""

                    if gateway is None:
                        gateway = ""

                    if ssid is None:
                        ssid = ""

                    str = "{mode: \"CLIENT\", ip: \"" + ip + "\", netmask: \"" + netmask + "\", gateway: \"" + gateway + "\", ssid: \"" + ssid + "\"}"
                    connection.sendall(str)

                data = connection.recv(1024)
                if data == "":
                    logger.debug("Socket closed remotely")
                    break
                self.callback(data)

            logger.debug("Sent data")
        except:
            logger.exception("Problem handling request")
        finally:
            logger.debug("Closing socket")
            connection.close()
Exemplo n.º 3
0
def startServer():
    global server

    check_network_status()

    # start tcp server
    logging.basicConfig(level=logging.DEBUG)
    p = SafeConfigParser()
    p.read(constant.HOME + '/config.ini')

    ip = CLI.get_ip()

    port = p.getint('TCP', 'port')
    cmd = "sudo fuser -k " + str(port) + "/tcp"
    print(cmd)
    os.popen(cmd)
    server = Server(ip, port, on_receive_data)

    try:
        print "Listening"
        server.start()
    except Exception, e:
        print str(e)