Example #1
0
def autoconnect_command(interface):
    ssids = [cell.ssid for cell in Cell.all(interface)]
    connected = False
    for scheme in [
            Scheme.find('wlan0', s)
            for s in ['scheme-' + str(x) for x in range(1, 6)]
    ]:
        ssid = scheme.options.get('wpa-ssid',
                                  scheme.options.get('wireless-essid'))
        if ssid in ssids:
            sys.stderr.write('Connecting to "%s".\n' % ssid)
            try:
                scheme.activate()
                connected = True
            except ConnectionError:
                print "Failed to connect to %s." % scheme.name
                continue
            connected = True
            break

    if not connected:
        try:
            s = Scheme.find('wlan0', 'hotspot')
            s.activate()
        except ConnectionError:
            print "hotspot is created."
Example #2
0
File: weech.py Project: nbdy/weech
 def connect(interface, password, ssid):
     if Utils.is_saved(interface, ssid):
         Scheme.find(interface, ssid).activate()
         return True
     c = Utils.get_cell(ssid, interface)
     if c is None:
         return False
     s = Scheme.for_cell(interface, ssid, c, password)
     s.save()
     s.activate()
     return True
Example #3
0
def testmethod_1():
    print "Method testmethod_1 in class testclass_5"
    print "Method Assign IP address by static in class testclass_5"
    scheme = Scheme.find('wlan0','1234')
    time.sleep(5)
    scheme.activate()
    static_test = UITest()
    static_test.static_config_retest('192.168.100.243','255.255.255.0','0.0.0.0','0.0.0.0')
    browser = webdriver.Firefox()
    browser.get('http://172.16.9.9')
    time.sleep(3)
    ipConfigHeadIcon_value = browser.find_element_by_id("ipConfigHeadIcon").get_attribute('src')
    known_ipConfigHeadIcon_value = 'http://172.16.9.9/images/dhcpgreen.png'
    assert known_ipConfigHeadIcon_value == ipConfigHeadIcon_value
    ipConfigTitle_value = browser.find_element_by_id("ipConfigTitle").text
    assert ipConfigTitle_value == '192.168.100.243'
    print("ipConfigTitle = %s" % ipConfigTitle_value)
    browser.find_element_by_id("ipConfigHeadIcon").click()
    time.sleep(1)
    #dhcp_name = browser.find_element_by_id("dhcpName").text
    time.sleep(1)
    #dhcp_subnet = browser.find_element_by_id("dhcpSubnet").text
    time.sleep(1)
    dhcp_dns1 = browser.find_element_by_id("dhcpDns1").text
    time.sleep(1)
    print(dhcpname)
    print(dhcp_subnet)
    print(dhcp_dns1)
    #assert dhcp_name == u'Server:'
    #assert dhcp_subnet == u'Subnet:255.255.255.0'
    #assert dhcp_dns1 == u'DNS:'
    browser.quit()
Example #4
0
File: weech.py Project: nbdy/weech
 def parse():
     c = Configuration()
     i = 0
     while i < len(argv):
         a = argv[i]
         if a in ["--help"]:
             Configuration.help()
         elif a in ["-h", "--host"]:
             c.host = argv[i + 1]
         elif a in ["-p", "--port"]:
             c.port = int(argv[i + 1])
         elif a in ["-d", "--debug"]:
             c.debug = True
         elif a in ["--add-scheme"]:
             for iface in argv[i + 1].split(","):
                 if iface in interfaces():
                     print(iface, argv[i + 3], argv[i + 2])
                     Utils.connect(iface, argv[i + 3], argv[i + 2])
                 else:
                     print(iface, "not in", interfaces())
             exit()
         elif a in ["--get-scheme"]:
             print(Scheme.find(argv[i + 1], argv[i + 2]))
             exit()
         i += 1
     return c
Example #5
0
def scanWifi():
	while 1:
		cellName =None
		cellList = Cell.all('wlan0')


		print "Scan Around Cell"

		for cell in cellList:
			if cell.ssid == 'carcar5':
				cellName =cell


		if cellName is None:
			print "Can not found <carcar5> try again"
			time.sleep(1)
			continue
		else :
			temp = Scheme.find('wlan0','home')
			if temp is not None:
				temp.delete()

			scheme = Scheme.for_cell('wlan0', 'home',cellName, passKey)
			scheme.save()
			scheme.activate()
				
			print "Try connect to <carcar5>"
			myIp = commands.getoutput("hostname -I")
			print "Connection Success my Ip is : " + myIp
			return True
Example #6
0
def wifiscan():
	Cell.all('wlan0')
	allSSID = list(Cell.all("wlan0"))[0]
	myssid = Scheme.for_cell('wlan0','home',allSSID,target_pwd)
	myssid.activate()
	
	myssid = Scheme.find('wlan0','home')
	myssid.activate()
Example #7
0
def connect_to_wifi(name):
    try:
        scheme = Scheme.find('wlan0', name)
        scheme.activate()
        time.sleep(10)
    except:
        print("trying to recconect")
        scheme.activate()
        time.sleep(10)
Example #8
0
def auto_connect(ap, adapter):
    # Attempt connection on known available networks
    for cell in list_networks(ap):
        # List networks from AP interface (so our own network is excluded)
        scheme = Scheme.find(adapter, cell.ssid)
        if activate_scheme(scheme):
            # Connected
            return cell.ssid
    # Failed to connect
    return False
Example #9
0
def tryToConnect():
    global connected
    file = open('.known_wifi', 'r')
    for line in file:
        scheme = Scheme.find(wifiInterface, line)
        if scheme:
            try:
                scheme.activate()
            except ConnectionError:
                continue
            connected = True
    connected = False
Example #10
0
File: main.py Project: drwonky/NC
    def wifi_reconnect(self):
        wifiap = self.config.get('networking', 'wifiap')
        wifi_iface = self.config.get('networking', 'wifi_iface')

        try:
            scheme = Scheme.find(wifi_iface, wifiap)
            if scheme != None:
                activatethread = Thread(target=self.activate_thread,
                                        args=(scheme.activate, ))
                activatethread.start()
        except:
            pass
Example #11
0
def connect_to_ap(log):
    """Function that will connect to wifi with the given parameters"""

    log.log("Connecting to " + WIFI_SSID + " using " + WIFI_INTERFACE)

    # Complicated way to account for the file not existing
    # Just tries to find if a scheme exists in interfaces
    try:
        scheme = Scheme.find(WIFI_INTERFACE, WIFI_PROFILE)
    except(IOError,err):
        log.log(err)
        log.log("WARNING: Most likely file was not found. Making one.")
        scheme = None
        if not os.path.isdir(INTERFACE_DIR):
            os.mkdir(INTERFACE_DIR, 0755)
            os.open(INTERFACE_FILE, 0644).close()
        elif not os.path.isfile(INTERFACE_FILE):
            os.open(INTERFACE_FILE, 0644).close()

    # If the scheme was not found or if it was found and didn't activate,
    # look for the ssid, save it, and connect to it.
    if scheme == None:
        cells = Cell.all(WIFI_INTERFACE)
        for cell in cells:
            if cell.ssid == WIFI_SSID:
                scheme = Scheme.for_cell(WIFI_INTERFACE,
                                         WIFI_PROFILE,
                                         cell,
                                         passkey=WIFI_PASS)
                scheme.save()
                break
    if scheme == None:
        log.log("ERROR: SSID " + WIFI_SSID + " was not found.")
        return False

        if scheme.activate() == False:
            log.log("ERROR: Could not connect to " + WIFI_SSID + ".")
            return False
    else:
        try:
            res = scheme.activate()
        # This can throw a lot of errors, let's just catch them all for now
        except:
            scheme.delete()
            #TODO delete the old scheme and add a new one. Possibly for password change
            log.log("ERROR: Could connect to " + WIFI_SSID)
            return False

    log.log("Successfully connected to " + WIFI_SSID + ".")
    return True
def connect_to_wifi(interface, name, cell, password):
    scheme = Scheme.for_cell(interface, name, cell, password)
    previous_scheme = Scheme.find(interface, name)
    if previous_scheme is not None:
        previous_scheme.delete()

    print scheme
    if scheme.find(interface, cell) is None:
        scheme.save()

    try:
        scheme.activate()
    except subprocess.CalledProcessError, e:
        print "Error: ", e.output
        return False
def scanWifi():
	while 1:	
		cellName=None
		#Wifi scannig use interface 'wlan0'
		cellList = Cell.all(iface)


		print "Network::scanWifi: Scan Around Cell"
		
		#find in cellList 
		for cell in cellList:
			if cell.ssid == ssid:
				cellName =cell


		if cellName is None:
			print "Network::scanWifi: Can not found <carcar5> try again"
			time.sleep(1)
			continue

		# if there is 'carcar5' ap 
		# Make connection 
		else :
			temp = Scheme.find(iface,nickname)
			if temp is not None:
				temp.delete()

			scheme = Scheme.for_cell(iface,nickname,cellName, passKey)
			scheme.save()
			scheme.activate()
				
			print "Network::scanWifi: Try connect to <carcar5>"
			myIp = commands.getoutput("hostname -I")
			print "Network::scanWifi: Connection Success my Ip(" + myIp + ")"

			childPid = os.fork()
			#print "after os.fork() " + str(pid)
			#print str(os.getpid()) + "--> child Pid : " + str(childPid)
			# Parent process : Send Data	
			if childPid:
				#print "Parent PID : " + str(os.getpid()) + " , Child PID : "+ str(childPid)
				sendData(childPid)


			# Child process : Receive Data
			else :
				#print "Child PID : " + str(os.getpid()) + " Parent PID : " + str(os.getppid())	
				receiveData()
Example #14
0
def _scheme_find(iface, ssid):
    """
    find a connection scheme for deletion

    :param iface: network interface
    :param ssid: network name
    :return: the scheme that matches the arguments
    """

    scheme = Scheme.find(iface, ssid)

    if scheme is None:
        # scheme doesn't exist, raise exception
        raise WifiException("scheme {}: not found".format(ssid), 404)

    return scheme
Example #15
0
def connectToWifi(ssid, passd):
    try:
        for elm in WlanCell:
            if elm.ssid == ssid:
                tmp = Scheme.find('wlan0', ssid)
                if tmp is not None:
                    tmp.delete()
                scheme = Scheme.for_cell('wlan0', ssid, elm, passd)
                scheme.save()
                scheme.activate()
            print("Connected To Wifi " + ssid)
            return True
        return False
    except Exception:
        print("Error by Connecting with " + ssid)
        return False
Example #16
0
def wifi(display, conf):
    if conf.get("wifi") and not get_current_wifi():
        cells = Cell.all(conf["wifi"]["interface"])
        for i in cells:
            scheme = Scheme.find(conf["wifi"]["interface"],_name(i))
            if not scheme:
                if i.ssid in conf["wifi"]["networks"]:
                    display.animateRow(0,"Preparing " + i.ssid)
                    scheme = Scheme.for_cell(
                        conf["wifi"]["interface"], _name(i),
                        i, conf["wifi"]["networks"][i.ssid])
                    scheme.save()
            if scheme:
                display.animateRow(0,"Trying " + scheme.options["wpa-ssid"])
                scheme.activate()
                return True
        return False
Example #17
0
def connect(esid, passkey=None, intf='wlan0'):
	cells = Cell.where(intf, lambda c: c.ssid == esid);

	if len(cells) == 0:
		raise LookupError('Network was not found');

	if len(cells) > 1:
		raise LookupError('Sorry, network SSID is ambiguous');

	scheme = Scheme.for_cell(intf, STORED_SCHEME_NAME, cells[0], passkey);

	old = Scheme.find(intf, STORED_SCHEME_NAME);
	if old is not None:
		old.delete();

	scheme.save();
	scheme.activate();
Example #18
0
def connect(adapter, ssid, psk=None, quiet=False):
	if not quiet:
		print "***setting up wireless adapter***"
	signal = []

	# get a list of all the available SSIDs that match the arg ssid
	cells = Cell.where(adapter, lambda x: x.ssid == ssid)
	print cells
	if len(cells) == 0:
		if not quiet:
			print "Cannot find SSID:", ssid
		return False

	# find the SSID with the best signal strength and select it as the cell to connect to
	for c in cells:
		signal.append(c.signal)

	max_signal = max(signal)
	max_index = signal.index(max_signal)
	cell = cells[max_index]
	scheme = Scheme.for_cell(adapter, ssid, cell, passkey=psk)

	# overwrite the scheme if already in '/etc/network/interfaces'
	# save it to '/etc/network/interfaces' if not
	if Scheme.find(adapter, ssid):
		scheme.delete()
		scheme.save()
	else:
		scheme.save()

	# attempt to connect to ssid
	try:
		if not quiet:
			print 'connecting to SSID:', cell.ssid
		scheme.activate()
		if not quiet:
			print 'connection successful'
		return True
	except:
		if not quiet:
			print('connection failed')
		return False
Example #19
0
def testmethod_2():
    print "Method testmethod_2 in class testclass_5"
    print "Method Dupicate IP address detection in class testclass_5"
    scheme = Scheme.find('wlan0','1234')
    time.sleep(5)
    scheme.activate()
    static_test = UITest()
    static_test.static_config_retest('192.168.100.1','255.255.255.0','0.0.0.0','0.0.0.0')
    browser = webdriver.Firefox()
    browser.get('http://172.16.9.9')
    time.sleep(3)
    ipConfigHeadIcon_value = browser.find_element_by_id("ipConfigHeadIcon").get_attribute('src')
    gateHeadIcon_value = browser.find_element_by_id("gateHeadIcon").get_attribute('src')
    wwwHeadIcon_value = browser.find_element_by_id("wwwHeadIcon").get_attribute('src')
    assert ipConfigHeadIcon_value == 'http://172.16.9.9/images/dhcpred.png'
    assert gateHeadIcon_value == 'http://172.16.9.9/images/gatewayblack.png'
    assert wwwHeadIcon_value == 'http://172.16.9.9/images/cloudblack.png'
    ipConfigTitle_value = browser.find_element_by_id("ipConfigTitle").text
    assert ipConfigTitle_value == '192.168.100.1'
    print("ipConfigTitle = %s" % ipConfigTitle_value)
    dhcp_test = UITest()
    dhcp_test.dhcp_config_retest()
    cloudHeadIcon_value = browser.find_element_by_id('cloudHeadIcon').is_displayed()
    print(cloudHeadIcon_value)
    browser.quit()
    if cloudHeadIcon_value == False:
        assert True
    else:
        assert False

    MONGOHQ_URL='mongodb://*****:*****@c494.candidate.42.mongolayer.com:10494/linksprinter-new-test'
    DATABASE = 'linksprinter-new-test'
    mongoClient = MongoClient(MONGOHQ_URL)
    linksprinter = mongoClient[DATABASE]
    collection=linksprinter.results
    print(collection)
    a = collection.find({"unit_mac": "00C017-090909","cached": True}).sort([("created_at",pymongo.DESCENDING)]).limit(1)
    aa = dict(a[0])
    dhcp_color = aa['ipConfigColor']
    ipconfig_value = aa['ipConfigIp']
    assert dhcp_color == u'red'
    assert ipconfig_value == u'192.168.100.1'
Example #20
0
def create_scheme(interface, ssid, passkey):
    # Save a couple SSID / passkey into Scheme object
    cell = Cell.where(interface, lambda c: c.ssid == ssid)
    # Get cell matching SSID
    if cell:
        # Delete previous duplicate
        previous = Scheme.find(interface, ssid)
        if previous:
            print "Deleting previous \"%s\" duplicate." % (ssid)
            previous.delete()
        # Instanciate Scheme for this Cell
        scheme = Scheme.for_cell(interface, ssid, cell[0], passkey)
        print "Saving WiFi scheme \"%s\"." % (ssid)
        try:
            scheme.save()
            return scheme
        except:
            print "Scheme could not be saved."
            pass
    return False
Example #21
0
def save(iface, ssid, passkey, db, lat=GPS_INF, lng=GPS_INF):
    """

    :param iface: network interface
    :param ssid: network name
    :param passkey: authentication passphrase
    :param db: sqlite3 database handle
    :param lat: latitude
    :param lng: longitude
    :return: the scheme just created
    """

    cell = _network_in_range(iface, ssid)
    scheme = Scheme.find(iface, ssid)

    # save scheme to file only if it does not exists
    if not scheme:
        scheme = _save_to_file(iface, ssid, cell, passkey)

    _save_to_db(iface, ssid, _get_hashed_passkey(scheme, cell), db, lat, lng)

    return scheme
Example #22
0
File: main.py Project: drwonky/NC
    def validate_pw(self, obj):
        self.popup.dismiss()
        scheme = Scheme.find(self.wifi_iface, self.ap.ssid)

        if scheme != None:
            scheme.delete()
            print('scheme found, deleting')

        scheme = Scheme.for_cell(self.wifi_iface, self.ap.ssid, self.ap,
                                 obj.text)
        scheme.save()

        progressbar = ProgressBar(max=10)
        progress = Popup(title='Connecting...',
                         size_hint=(None, None),
                         size=(400, 100),
                         content=progressbar)
        progress.open()

        activatethread = Thread(target=self.activate_thread, args=(scheme, ))
        activatethread.start()
        print('thread started')

        while self.activation_status is None:
            time.sleep(1)
            progressbar.value = (progressbar.value + 1) % 10
            print('tick')

        progress.dismiss()

        if self.activation_status:
            self.save_ap()
            print('activated')
        else:
            scheme.delete()
            self.ask_pass()
            print('failed, asking again')
        pass
def start_server():
    from wifi import Cell, Scheme
    try:
        network, passkey = get_creds()
    except Exception as e:
        print(e)
        print('starting webserver')
        os.system('sudo python webserver.py')
    myfi = Cell.all('wlan0')
    cell = [w for w in myfi if w.ssid == network]
    print('trying:', network)
    try:
        if len(cell) > 0:
            print('found a match')
        else:
            print('no matching network found')
        scheme = Scheme.for_cell('wlan0', 'myNetwork', cell[0], passkey)
        try:
            scheme.save()
        except Exception as e:
            print(e)
            print('matching scheme')
            scheme = Scheme.find('wlan0', 'myNetwork')
        try:
            print('activating network')
            scheme.activate()
            time.sleep(7)
            print('after attempting reconnect:')
            print(subprocess.check_output('ifconfig wlan0', shell=True))
        except Exception as e:
            print(e)
            print('something went wrong, rebooting web server')
            os.system('sudo ifconfig wlan0 down')
            os.system('sudo ifconfig wlan0 up')
            os.system('sudo python webserver.py')
    except Exception as e:
        print(e)
Example #24
0
def testmethod_4():
    print "Method testmethod_4 in class testclass_5"
    print "Method Assign IP address by static in class testclass_5"
    scheme = Scheme.find('wlan0','1234')
    time.sleep(5)
    scheme.activate()
    static_test = UITest()
    static_test.static_config('192.168.100.243','255.255.255.0','0.0.0.0','0.0.0.0')
    static_test.ping_config_retest('www.baidu.com')
    browser = webdriver.Firefox()
    browser.get('http://172.16.9.9')
    time.sleep(3)
    ipConfigHeadIcon_value = browser.find_element_by_id("ipConfigHeadIcon").get_attribute('src')
    #gateHeadIcon_value = browser.find_element_by_id("gateHeadIcon").get_attribute('src')
    #wwwHeadIcon_value = browser.find_element_by_id("wwwHeadIcon").get_attribute('src')
    assert ipConfigHeadIcon_value == 'http://172.16.9.9/images/dhcpgreen.png'
    #assert gateHeadIcon_value == 'http://172.16.9.9/images/gatewayblack.png'
    #assert wwwHeadIcon_value == 'http://172.16.9.9/images/cloudred.png'
    ipConfigTitle_value = browser.find_element_by_id("ipConfigTitle").text
    assert ipConfigTitle_value == '192.168.100.243'
    print("ipConfigTitle = %s" % ipConfigTitle_value)
    browser.find_element_by_id("ipConfigHeadIcon").click()
    time.sleep(1)
    dhcp_dns1 = browser.find_element_by_id("dhcpDns1").text
    time.sleep(1)
    print(dhcp_dns1)
    dhcp_name = browser.find_element_by_id("dhcpName").text
    time.sleep(1)
    print(dhcp_name)
    dhcp_subnet = browser.find_element_by_id("dhcpSubnet").text
    time.sleep(1)
    print(dhcp_subnet)
    assert dhcp_dns1 == u'DNS:'
    assert dhcp_name == u'Server:'
    assert dhcp_subnet == u'Subnet:255.255.255.0'
    browser.quit()
Example #25
0
ssid = 'JF2'
passkey = 'JF08310122'
_WIFI_NOT_FOUND = True

os.system('sudo ifdown ' + interface)
os.system('sudo ifup ' + interface)
print 'waiting for reset...'
time.sleep(10)

cells = Cell.all(interface)
for cell in cells:
    if str(cell.ssid) == ssid:
        print 'SSID found, please wait...'

        #        cell = Cell.all('wlan0')[1]
        scheme = Scheme.for_cell(interface, ssid, cell, passkey)
        if bool(Scheme.find(interface, ssid)) == False:
            if os.access('/etc/network/interfaces', os.W_OK) != True:
                os.system('sudo chmod 777 /etc/network/interfaces')
            scheme.save()
            print 'Writing config to interfaces file...'

        scheme.activate()
        _WIFI_NOT_FOUND = False
        break

if _WIFI_NOT_FOUND:
    print 'Designated SSID not found.'
else:
    print 'Wifi is available now!'
Example #26
0
 def activate_scheme(self, ssid):
     scheme = Scheme.find(self.iface, ssid)
     if scheme is None:
         return False
     else:
         scheme.activate()
from wifi import Cell, Scheme
scheme = Scheme.find('wlan0', 'labpump123')
scheme.activate()
Example #28
0
def testmethod_3():
    print "Method testmethod_3 in class testclass_5"
    print "Method set ip addr, subnet, and dns which is out of subnet in class testclass_5"
    scheme = Scheme.find('wlan0','1234')
    time.sleep(5)
    scheme.activate()
    static_test = UITest()
    static_test.static_config('192.168.100.243','255.255.255.0','0.0.0.0','192.168.1.100')
    static_test.ping_config_retest('www.baidu.com')
    browser = webdriver.Firefox()
    browser.get('http://172.16.9.9')
    time.sleep(3)
    ipConfigHeadIcon_value = browser.find_element_by_id("ipConfigHeadIcon").get_attribute('src')
    gateHeadIcon_value = browser.find_element_by_id("gateHeadIcon").get_attribute('src')
    wwwHeadIcon_value = browser.find_element_by_id("wwwHeadIcon").get_attribute('src')
    assert ipConfigHeadIcon_value == 'http://172.16.9.9/images/dhcpgreen.png'
    assert gateHeadIcon_value == 'http://172.16.9.9/images/gatewayblack.png'
    assert wwwHeadIcon_value == 'http://172.16.9.9/images/cloudred.png'
    ipConfigTitle_value = browser.find_element_by_id("ipConfigTitle").text
    assert ipConfigTitle_value == '192.168.100.243'
    print("ipConfigTitle = %s" % ipConfigTitle_value)
    browser.find_element_by_id("ipConfigHeadIcon").click()
    time.sleep(1)
    dhcp_dns1 = browser.find_element_by_id("dhcpDns1").text
    time.sleep(1)
    print(dhcp_dns1)
    assert dhcp_dns1 == u'DNS:192.168.1.100'
    browser.find_element_by_id("wwwHeadIcon").click()
    time.sleep(1)
    www_ip = browser.find_element_by_id("wwwIp").text
    time.sleep(1)
    print(www_ip)
    assert www_ip == u"IP:"
    dhcp_test = UITest()
    dhcp_test.dhcp_config_retest()
    cloudHeadIcon_value = browser.find_element_by_id('cloudHeadIcon').is_displayed()
    print(cloudHeadIcon_value)
    browser.quit()
    if cloudHeadIcon_value == False:
        assert True
    else:
        assert False
    MONGOHQ_URL='mongodb://*****:*****@c494.candidate.42.mongolayer.com:10494/linksprinter-new-test'
    DATABASE = 'linksprinter-new-test'
    mongoClient = MongoClient(MONGOHQ_URL)
    linksprinter = mongoClient[DATABASE]
    collection=linksprinter.results
    print(collection)
    a = collection.find({"unit_mac": "00C017-090909","cached": True}).sort([("created_at",pymongo.DESCENDING)]).limit(1)
    aa = dict(a[0])
    dhcp_color = aa['ipConfigColor']
    www_color = aa['wwwColor']
    dns_value = aa['dns']
    www_value = aa['www']
    dns_value_1 = dns_value[0]
    dns_value_2 = dns_value_1['dnsIp']
    www_value_1 = www_value[0]
    www_value_2 = www_value_1['wwwIp']
    assert dhcp_color == u'green'
    assert www_color == u'red'
    assert dns_value_2 == u'192.168.1.100'
    assert www_value_2 == u''
Example #29
0
from wifi import Cell, Scheme
Cell.all('wlan0')
cell = Cell.all('Wi-Fi)[0]
scheme = Scheme.for_cell('wlan0', 'home', cell, passkey)
scheme.save()
scheme.activate()

scheme = Scheme.find('wlan0', 'home')
scheme.activate()
Example #30
0
 def find_scheme(self, ssid):
     scheme = Scheme.find(self.iface, ssid)
     if scheme is None:
         return False
     else:
         return True
Example #31
0
def deleteUserWifiIfPresent():
    scheme = Scheme.find('wlan0', 'userWifi')
    if scheme is not None:
        scheme.delete()
salir = 0
cread_config_Class = cread_config()

while not(salir):
    if estado== -1:
        # Init. borramos las redes antuguas.
        try:
            log(2, "====== Init Connect wifi =======")
            wifissid = cread_config_Class.read_config("wifi_ssid")
            wificode = cread_config_Class.read_config("wifi_code")
            wait = 0.1
            conectado=0
            internet=0
            estado = 0            
            try:
                scheme = Scheme.find("wlan0", wifissid)
                if (scheme != None ):
                    scheme.delete()
                    log(0, "scheme borrado.")
            except:
                scheme = None
        except:
            # error.
            log(5, "Imposible leer la configuracion"  )
            wifi = 0
            conectado=0
            internet=0
            estado = 0
            wait= 10
    elif estado==0:
        # leer configuracion
Example #33
0
 def _findFromSavedList(self, ssid):
     cell = Scheme.find('wlan0', ssid)
     if cell:
         return cell
     return False
Example #34
0
def testmethod_2():
    print "Method testmethod_2 in class testclass_4"
    print "Method GW empty, DNS empty, WWW IP, same subnet, reachable in class testclass_4"
    __author__ = 'bzhang4'
    scheme = Scheme.find('wlan0','1234')
    time.sleep(5)
    scheme.activate()
    ui_operation = UITest()
    ui_operation.static_config('192.168.2.33','255.255.255.0','0.0.0.0','0.0.0.0')
    time.sleep(5)
    ui_operation.ping_config_retest('192.168.2.200')
    browser = webdriver.Firefox()
    browser.get('http://172.16.9.9')
    time.sleep(3)
    ipConfig_value = browser.find_element_by_id("ipConfigHeadIcon").get_attribute('src')
    GW_value = browser.find_element_by_id("gateHeadIcon").get_attribute('src')
    cloud_value = browser.find_element_by_id("wwwHeadIcon").get_attribute('src')
    print(cloud_value)
    known_ipConfig_value = 'http://172.16.9.9/images/dhcpgreen.png'
    known_GW_value = 'http://172.16.9.9/images/gatewayblack.png'
    known_cloud_value = 'http://172.16.9.9/images/cloudgreen.png'
    assert ipConfig_value == known_ipConfig_value
    assert GW_value == known_GW_value
    assert cloud_value == known_cloud_value
    ser = serial.Serial()
    ser.baudrate = 115200
    ser.port = '/dev/ttyUSB0'
    ser.open()
    assert ser.isOpen()
    ser.write('leds\n')
    ser.inWaiting()
    b = ser.read(110)
    str1 = bytes.decode(b)
    print(str1)
    dhcp_led = 'DHCP:\tGREEN'
    GW_led = 'GW:\tNONE'
    #www_led = 'WWW:\tRED'
    assert str1.find(dhcp_led) != -1
    assert str1.find(GW_led) != -1
    dhcp_test = UITest()
    dhcp_test.dhcp_config_retest()
    time.sleep(5)
    cloudHeadIcon_value = browser.find_element_by_id('cloudHeadIcon').is_displayed()
    print(cloudHeadIcon_value)
    browser.quit()
    if cloudHeadIcon_value == False:
        assert True
    else:
        assert False
    MONGOHQ_URL='mongodb://*****:*****@c494.candidate.42.mongolayer.com:10494/linksprinter-new-test'
    DATABASE = 'linksprinter-new-test'
    mongoClient = MongoClient(MONGOHQ_URL)
    linksprinter = mongoClient[DATABASE]
    collection=linksprinter.results
    print(collection)
    a = collection.find({"unit_mac": "00C017-090909","cached": True}).sort([("created_at",pymongo.DESCENDING)]).limit(1)
    aa = dict(a[0])
    dhcp_color = aa['ipConfigColor']
    www_color = aa['wwwColor']
    print('The ipConfigColor is %s' % dhcp_color)
    print('The wwwColor is %s' % www_color)
    assert dhcp_color == u'green'
    assert www_color == u'green'
Example #35
0
#wifi password
passKey = 'raspberry'
scheme = None


#Same as "sudo iwlist wlan0 scan"
cellName = None
cellList = Cell.all('wlan0')

#Find cell information which ssid is 'carcar5' 
for cell in cellList:
	if cell.ssid == 'carcar5':
		cellName = cell

#Connect to wifi
scheme = Scheme.find('wlan0','home')
if scheme is None:
	scheme = Scheme.for_cell('wlan0', 'home', cellName, passKey)
	scheme.save()
	scheme.activate()
else :
	scheme.delete()

######################################################################


"""

###################### Monitoring Connection ######################

class MonitoringConnection(threading.Thread):
Example #36
0
def testmethod_1():
    print "Method testmethod_1 in class testclass_6"
    print "Method tcp port reachable in class testclass_6"
    scheme = Scheme.find('wlan0', '1234')
    time.sleep(5)
    scheme.activate()
    dhcp_test = UITest()
    dhcp_test.tcp_config('192.168.2.100', '80')
    time.sleep(3)
    dhcp_test.dhcp_config_retest()
    browser = webdriver.Firefox()
    browser.get('http://172.16.9.9')
    time.sleep(3)
    wwwHeadIcon_value = browser.find_element_by_id(
        "wwwHeadIcon").get_attribute('src')
    assert wwwHeadIcon_value == 'http://172.16.9.9/images/cloudgreen.png'
    browser.find_element_by_id('wwwHeadIcon').click()
    type_value = browser.find_element_by_id('wwwType').text
    port_value = browser.find_element_by_id("wwwPort").text
    ip_value = browser.find_element_by_id("wwwIp").text
    pingres_value = browser.find_element_by_id("wwwPingRes").text
    list1 = list(pingres_value)
    c = type(list1)
    print(c)
    #print('type_value')
    #print(type_value)
    #print('port_value')
    #print(port_value)
    #print('ip_value')
    #print(ip_value)
    print('pingres_value')
    print(pingres_value)
    assert type_value == u'Type:TCP'
    assert port_value == u'Port:80(HTTP)'
    assert ip_value == u'IP:192.168.2.100'
    #cloudHeadIcon_value = browser.find_element_by_id('cloudHeadIcon').get_attribute('src')
    cloudHeadIcon_value = browser.find_element_by_id(
        'cloudHeadIcon').is_displayed()
    print(cloudHeadIcon_value)
    browser.quit()
    if cloudHeadIcon_value == False:
        assert True
    else:
        assert False
    MONGOHQ_URL = 'mongodb://*****:*****@c494.candidate.42.mongolayer.com:10494/linksprinter-new-test'
    DATABASE = 'linksprinter-new-test'
    mongoClient = MongoClient(MONGOHQ_URL)
    linksprinter = mongoClient[DATABASE]
    collection = linksprinter.results
    print(collection)
    a = collection.find({
        "unit_mac": "00C017-090909",
        "cached": False
    }).sort([("created_at", pymongo.DESCENDING)]).limit(1)
    aa = dict(a[0])
    www_color = aa['wwwColor']
    www_value = aa['www']
    www_value_1 = www_value[0]
    wwwtype_value = www_value_1['wwwType']
    wwwip_value = www_value_1['wwwIp']
    wwwport_value = www_value_1['wwwPort']
    list2 = www_value_1['wwwConnect']
    a = type(list2)
    print(list2)

    #print('www_color')
    #print(www_color)
    #print('wwwtype_value')
    #print(wwwtype_value)
    #print('wwwip_value')
    #print(wwwip_value)
    #print('wwwport_value')
    #print(wwwport_value)
    #b = type(wwwport_value)
    #print(b)

    assert www_color == u'green'
    assert wwwtype_value == u'TCP'
    assert wwwip_value == u'192.168.2.100'
    assert wwwport_value == 80
Example #37
0
from wifi import Scheme
import time

scheme = Scheme.find('wlan0', 'userWifi')
if scheme is not None:
    print("not")
    scheme.delete()
else:
    print("none")
Example #38
0
 def connect_net_linux(self, wifi):
     return Scheme.find(self.iface, wifi[1]).activate()
Example #39
0
# connect to network
from wifi import Cell, Scheme

# wifi information
wifi_ssid = "labpump123"
wifi_password = "******"

# machine information
port = Cell.all('wlan0')[0]

print "Connecting..."

try:
    scheme = Scheme.for_cell('wlan0', wifi_ssid, port, wifi_password)
    scheme.save()

except:
    scheme = Scheme.find('wlan0', wifi_ssid)

finally:
    scheme.activate();

# check internet connection
from pythonwifi.iwlibs import Wireless

network = Wireless('wlan0')
print "Connected with "+network.getEssid()+"."
print ("" if network.getMode()=="Managed" else "Not ")+"Secured Connection."