本文整理汇总了Python中wifi.Cell.all方法的典型用法代码示例。如果您正苦于以下问题:Python Cell.all方法的具体用法?Python Cell.all怎么用?Python Cell.all使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类wifi.Cell
的用法示例。
在下文中一共展示了Cell.all方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: ScanWIFI
# 需要导入模块: from wifi import Cell [as 别名]
# 或者: from wifi.Cell import all [as 别名]
def ScanWIFI(card):
try:
wifiCell = Cell.all(card)
except:
wifiCell = Cell.all('wlan0')
SendData("Something went wrong... using wlan0")
for i in range(0,len(wifiCell)):
SendData(str(wifiCell[i]) + " is encrypted: "+ str(wifiCell[i].encrypted) + "= " + str(wifiCell[i].encryption_type) + " | address: " +str(wifiCell[i].address))
SendData("ScanWIFI-finished")
示例2: wifi_scan
# 需要导入模块: from wifi import Cell [as 别名]
# 或者: from wifi.Cell import all [as 别名]
def wifi_scan():
global connected
reconnected = 0
while 1:
print "Reconnected %d" %reconnected
#Connected, check if still in range
if connected != "":
aps = Cell.all(interface)
inrange = 0
for ap in range(0, len(aps)):
if aps[ap].ssid == connected and aps[ap].signal <= -50:
inrange = 1
if inrange != 1:
connected = ""
else:
time.sleep(20)
#Not connected
else:
aps = Cell.all(interface)
for ap in range(0, len(aps)):
if aps[ap].ssid in known_ssids:
passwd = known_ssids_pass[known_ssids.index(aps[ap].ssid)]
scheme = Scheme.for_cell(interface, "target", aps[ap], passwd)
scheme.delete()
scheme.save()
try:
scheme.activate()
connected = aps[ap].ssid
reconnected += 1
break
except:
print "Could not connect"
continue
#connect to the AP and stop scanning (return connected = ssid?)
else:
for ap in range(0, len(aps)):
if aps[ap].encrypted == False and connected == "":
scheme = Scheme.for_cell(interface, "target", aps[ap])
scheme.delete()
scheme.save()
try:
scheme.activate()
connected = aps[ap].ssid
reconnected += 1
break
except:
print "could not connect"
continue
else:
time.sleep(10)
示例3: scan
# 需要导入模块: from wifi import Cell [as 别名]
# 或者: from wifi.Cell import all [as 别名]
def scan(self):
print "Scan Start"
while True:
cell = Cell.all(interface)
print "Rescanning"
timer = 0
while timer < 100:
timer +=1
S = []
count = 0
for c in cell:
count += 1
#print ":"+ str(count), " ssid:", c.ssid
#create dictionary with informnation on the accesss point
SSIDS = {"no" : count ,"ssid": c.ssid, "channel":c.channel,"encrypted":c.encrypted, \
"frequency":c.frequency,"address":c.address, "signal":c.signal, "mode":c.mode}
#if not db.search((where('ssid') == ap["ssid"])) == []:
# res = db.search(where('ssid') == c.ssid)
#print db.search(where('ssid') == c.ssid)
print "=----------------------------------"
# print c.address
print "---------------------------------------"
if db.contains(where('ssid') == c.ssid):
print (db.contains((where('ssid') == c.ssid) & (where('address') == str(c.address))))
示例4: network_wlan
# 需要导入模块: from wifi import Cell [as 别名]
# 或者: from wifi.Cell import all [as 别名]
def network_wlan():
ALL_IP = ip_addresses()
url = request.url_root
url = url[7:-1]
dicts = {
'ALL_IP': ALL_IP,
'IP': ALL_IP['IP'],
'using_desktop': using_desktop(),
'url': url,
}
form=ConnectWifi(request.form)
#dsadsa
cell = Cell.all('wlan0')
ssid=[]
for c in cell:
ssid.append(c.ssid)
if request.method == 'POST':
wifi_name = form.ssid.data
password = form.password.data
cmd = 'nmcli dev wifi connect ' + wifi_name + ' password ' + password
system(cmd)
return cmd
return render_template('network/network_wlan.html',
wlan=ssid, form=form, dicts=dicts)
示例5: sample_interface_neighbourhood
# 需要导入模块: from wifi import Cell [as 别名]
# 或者: from wifi.Cell import all [as 别名]
def sample_interface_neighbourhood(network_interface, networks = None, network_states = None):
"""sample interface neighbourhood"""
networks = networks if networks else {}
network_states = network_states if network_states else {}
timestamp = str(datetime.datetime.now())
cells = Cell.all(network_interface)
for cell in cells:
network_key = render_network_key(cell.ssid, cell.address)
if network_key not in networks.keys():
network = new_network(
cell.address, cell.ssid, cell.frequency,
cell.encryption_type if cell.encrypted else None, cell.encrypted, cell.mode,
cell.bitrates, cell.channel)
networks[network_key] = network
network_states[network_key] = new_network_state()
network_state = network_states[network_key]
network_state['time'].append(time)
network_state['signal'].append(cell.signal)
network_state['quality'].append(cell.quality)
return networks, network_states
示例6: run
# 需要导入模块: from wifi import Cell [as 别名]
# 或者: from wifi.Cell import all [as 别名]
def run(self):
#try:
#print Cell.all(self.interface)[0]
cell = Cell.all(self.interface)[0]
scheme = Scheme.for_cell(self.interface, self.ssid, cell, self.passphrase)
#scheme.save()
self._return = scheme.activate()
示例7: testWifi
# 需要导入模块: from wifi import Cell [as 别名]
# 或者: from wifi.Cell import all [as 别名]
def testWifi(GPIO,pinDict,x2,mbRetries,wifiNetwork,wifiRetries):
powerOn(GPIO,pinDict,"IO1")
print ("=====================")
print (datetime.datetime.now().strftime("%Y.%m.%d_%H.%M.%S"))
print ("=====================")
#NEED TO TURN ON WIFI SWITCH
searchString=wifiNetwork
retries=wifiRetries
sleepSec = 2
for i in range(0,retries):
ssids=[cell.ssid for cell in Cell.all('wlan0')]
print("List of all networks found:",ssids)
for ssid in ssids:
if (searchString in ssid):
done=True
print("Attempt", i+1, "of", retries, "was successful")
print("Found network:",ssid)
break
else:
done=False
if(done):
return ["Pass"]
else:
print("Failed to find a network with", searchString, "in it on attempt", i+1, "of", retries)
if(i+1<retries):
print("Waiting", sleepSec, "seconds and retrying...")
time.sleep(sleepSec)
else:
print("Failed to find X2 network")
return ["Fail-Network not found"]
示例8: ScanForNetworks
# 需要导入模块: from wifi import Cell [as 别名]
# 或者: from wifi.Cell import all [as 别名]
def ScanForNetworks(self):
cells = Cell.all(WIRELESS)
listOfCells = []
for cell in cells:
if str(cell.ssid) not in listOfCells:
listOfCells.append(str(cell.ssid))
return(listOfCells)
示例9: __init__
# 需要导入模块: from wifi import Cell [as 别名]
# 或者: from wifi.Cell import all [as 别名]
def __init__(self):
'''
Constructor method
'''
# Default directory & interface
self.cwd = os.getcwd()
self.iface = 'wlan0'
# Try to get wireless gateway details,
# unless there's no active connection
try:
self.ping_ip, self.gw_mac = self.getGateway()
except:
self.ping_ip = self.gw_mac = None
print('Error! \nCheck your connection!')
finally:
pass
# Get the Gateway SSID
try:
cell = Cell.all(self.iface)
x, y = str(list(cell)[0]).split('=')
self.ssid = y.strip(')')
except:
self.ssid = 'Offline'
示例10: scanWifi
# 需要导入模块: from wifi import Cell [as 别名]
# 或者: from wifi.Cell import all [as 别名]
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
示例11: get_location
# 需要导入模块: from wifi import Cell [as 别名]
# 或者: from wifi.Cell import all [as 别名]
def get_location(self):
"""Obtains the physical location using nearby Wi-Fi networks.
:returns: a Dict containing the lat & lon for the current location.
According to Google's API specification, two or more access points are
required for a result to be returned. In case a result is not returned,
or another error occurs, a LocationError is raised.
"""
# Get full information for all visible access points
networks = Cell.all(self.interface)
addresses = []
# Extract just the MAC addresses
for network in networks:
addresses.append({'macAddress': network.address})
json_response = requests.post(
GOOGLE_LOCATION_URL.format(GOOGLE_API_KEY),
data=json.dumps({'wifiAccessPoints': addresses}),
headers=JSON_REQUEST_HEADERS
).json()
# Handle Google returning an error.
if "error" in json_response:
raise LocationError("Unable to determine location")
else:
return {
'lat': json_response['location']['lat'],
'lon': json_response['location']['lng']
}
示例12: scan
# 需要导入模块: from wifi import Cell [as 别名]
# 或者: from wifi.Cell import all [as 别名]
def scan(self, event=None):
LOG.info("Scanning wifi connections...")
networks = {}
status = self.get_status()
for cell in Cell.all(self.iface):
if "x00" in cell.ssid:
continue # ignore hidden networks
update = True
ssid = cell.ssid
quality = self.get_quality(cell.quality)
# If there are duplicate network IDs (e.g. repeaters) only
# report the strongest signal
if networks.__contains__(ssid):
update = networks.get(ssid).get("quality") < quality
if update and ssid:
networks[ssid] = {
'quality': quality,
'encrypted': cell.encrypted,
'connected': self.is_connected(ssid, status)
}
self.ws.emit(Message("mycroft.wifi.scanned",
{'networks': networks}))
LOG.info("Wifi connections scanned!\n%s" % networks)
示例13: scan
# 需要导入模块: from wifi import Cell [as 别名]
# 或者: from wifi.Cell import all [as 别名]
def scan(iface):
exp_backoff=1
for _ in range(5):
results = []
for cell in Cell.all(iface):
c = {
'ssid': cell.ssid,
'frequency': cell.frequency,
'bitrates': cell.bitrates,
'encrypted': cell.encrypted,
'channel': cell.channel,
'address': cell.address,
'mode': cell.mode,
'quality': cell.quality,
'signal': cell.signal
}
if cell.encrypted:
c['encryption_type'] = cell.encryption_type
results.append(c)
results.sort(key=lambda x: x['signal'], reverse=True)
if (len(results) > 0):
break
sleep(exp_backoff)
exp_backoff *= 2
#retry
return jsonify(results=results)
示例14: get
# 需要导入模块: from wifi import Cell [as 别名]
# 或者: from wifi.Cell import all [as 别名]
def get(self):
cells = Cell.all('wlan0')
items = []
for cell in cells:
items.append(cell.__dict__)
self.write(json.dumps(items))
示例15: getWifiNetworks
# 需要导入模块: from wifi import Cell [as 别名]
# 或者: from wifi.Cell import all [as 别名]
def getWifiNetworks():
l=[]
i=0
scanned=False
while not scanned and i<3:
l=[]
try:
for cell in Cell.all('wlan0'):
try:
name=str(cell.ssid)
if len(name.strip())>1:
enc="None"
if cell.encrypted:
enc=cell.encryption_type
l.append((cell.signal,cell.encrypted,cell.ssid,enc))
except:
logging.warning("Failed to use cell, %s" , cell.ssid)
scanned=True
except: # please lets move this (wpa_cli scan / wpa_scan_results ? )
i+=1
time.sleep(1)
l.sort(reverse=True)
print l
return l