本文整理汇总了Python中wifi.scan.Cell.all方法的典型用法代码示例。如果您正苦于以下问题:Python Cell.all方法的具体用法?Python Cell.all怎么用?Python Cell.all使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类wifi.scan.Cell
的用法示例。
在下文中一共展示了Cell.all方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: update
# 需要导入模块: from wifi.scan import Cell [as 别名]
# 或者: from wifi.scan.Cell import all [as 别名]
def update(self):
"""Update Wifi stats using the input method.
Stats is a list of dict (one dict per hotspot)
:returns: list -- Stats is a list of dict (hotspot)
"""
# Reset stats
self.reset()
# Exist if we can not grab the stats
if not wifi_tag:
return self.stats
if self.input_method == 'local':
# Update stats using the standard system lib
# Grab network interface stat using the PsUtil net_io_counter method
try:
netiocounters = psutil.net_io_counters(pernic=True)
except UnicodeDecodeError:
return self.stats
for net in netiocounters:
# Do not take hidden interface into account
if self.is_hide(net):
continue
# Grab the stats using the Wifi Python lib
try:
wifi_cells = Cell.all(net)
except InterfaceError:
# Not a Wifi interface
pass
except Exception as e:
# Other error
logger.debug("WIFI plugin: Can not grab cellule stats ({})".format(e))
pass
else:
for wifi_cell in wifi_cells:
hotspot = {
'key': self.get_key(),
'ssid': wifi_cell.ssid,
'signal': wifi_cell.signal,
'quality': wifi_cell.quality,
'encrypted': wifi_cell.encrypted,
'encryption_type': wifi_cell.encryption_type if wifi_cell.encrypted else None
}
# Add the hotspot to the list
self.stats.append(hotspot)
elif self.input_method == 'snmp':
# Update stats using SNMP
# Not implemented yet
pass
return self.stats
示例2: tick
# 需要导入模块: from wifi.scan import Cell [as 别名]
# 或者: from wifi.scan.Cell import all [as 别名]
def tick():
'''
***REMOVE IF WE CAN TELL IF WE ARE CONNECTED
If there is only 1 wifi network, it means
that we are already connected or that there
is only 1 wifi network. Do nothing since the
user can try and connect to that network
on there own.
'''
'''
A list of the addresses of networks that are repetitive with each scan.
Make the noted and previous network lists global
'''
global prevNetworks
global notedNetworks
lastingNetworks = []
'''
Parse the data from the already parsed data of
Cell.all("wlan0") and turn it into a list of
the wifi networks each represented by the
Network class. When parsing, if a network has
the name of another in the list, keep/add
whichever network has the strongest signal.
If each have the same signal, choose the
current network being iterated over.
Ex: Two seperate xfinitywifi networks.
'''
liveNetworks = []
for network in Cell.all("wlan0"):
ssid = network.ssid
address = network.address
signal = round(int((network.quality.split("/")[0]))/.7)
encrypted = network.encrypted
parsedNetwork = Network(ssid,address,signal,encrypted)
if (getNetworkFromSSID(liveNetworks, ssid) is not None):
otherNetwork = getNetworkFromSSID(liveNetworks, ssid)
if (otherNetwork.signal <= signal):
removeNetwork(liveNetworks, ssid)
liveNetworks.append(parsedNetwork)
else:
liveNetworks.append(parsedNetwork)
'''
With our fresh set of live parsed networks,
we now need to compare them with our older
previous set of networks so that we can
update the vital list of lasting networks.
We also need to average out the signal from
the previous signal and current signal for
more accuracy and increase the amount of times
this network has been scanned in a row if it appears
in the list of old networks. We also need to add
its MAC Address if it's not already in the lasting
list of networks.
'''
for network in liveNetworks:
if (not(getNetworkFromMAC(prevNetworks,network.address) == None)):
oldNetwork = getNetworkFromMAC(prevNetworks,network.address)
network.count = (oldNetwork.count + 1)
network.signal = round((network.signal + oldNetwork.signal) / 2)
if (notedNetworks.count(network.address) == 0 and
lastingNetworks.count(network.address) == 0):
lastingNetworks.append(network.address)
'''
Run through our list of lasting networks and check
if each network has had an average signal of 50% or
above and has been scanned 3 times in a row. If so,
display the notification that the network is available
and remove it from the list of lasting network MACs.
Add it to the list of noted networks so it doesn't
get thrown back in the mix.
'''
'''
Remove noted network MAC addresses if they no longer are lasting
'''
removedMACS = []
for address in lastingNetworks:
network = getNetworkFromMAC(liveNetworks, address)
if (network.signal >= 50 and network.count >= 3):
removedMACS.append(address)
if (notedNetworks.count(address) == 0):
notedNetworks.append(address)
ssid = network.ssid
encrypted = None
if (network.encrypted is True):
encrypted = "Yes"
else:
encrypted = "No"
if ("x00" in str(ssid)):
ssid = "Unknown"
pynotify.init("netscan - " + network.ssid)
notification = pynotify.Notification("Network Detected",
#.........这里部分代码省略.........