本文整理汇总了Python中wifi.scan.Cell类的典型用法代码示例。如果您正苦于以下问题:Python Cell类的具体用法?Python Cell怎么用?Python Cell使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Cell类的19个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。
示例1: normalize
def normalize(cell_block):
# The cell blocks come in with every line except the first indented at
# least 20 spaces. This removes the first 20 spaces off of those lines.
lines = textwrap.dedent(' ' * 20 + cell_block).splitlines()
cell = Cell()
while lines:
line = lines.pop(0)
if line.startswith('Quality'):
for re_name, quality_re in quality_re_dict.items():
match_result = quality_re.search(line)
if match_result is not None:
cell.quality, signal = match_result.groups()
if re_name == 'relative':
actual, total = map(int, signal.split('/'))
cell.signal = db2dbm(int((actual / total) * 100))
else:
cell.signal = int(signal)
break
elif line.startswith('Bit Rates'):
values = split_on_colon(line)[1].split('; ')
# consume next line of bit rates, because they are split on
# different lines, sometimes...
while lines[0].startswith(' ' * 10):
values += lines.pop(0).strip().split('; ')
cell.bitrates.extend(values)
elif ':' in line:
key, value = split_on_colon(line)
key = normalize_key(key)
if key == 'ie':
if 'Unknown' in value:
continue
# consume remaining block
values = [value]
while lines and lines[0].startswith(' ' * 4):
values.append(lines.pop(0).strip())
if 'WPA2' in value:
cell.encryption_type = 'wpa2'
elif 'WPA' in value:
cell.encryption_type = 'wpa'
if key == 'frequency':
frequency, channel = frequency_re.search(value).groups()
cell.frequency = frequency
cell.channel = int(channel)
elif key in normalize_value:
setattr(cell, key, normalize_value[key](value))
# It seems that encryption types other than WEP need to specify their
# existence.
if cell.encrypted and not hasattr(cell, 'encryption_type'):
cell.encryption_type = 'wep'
return cell
开发者ID:Mondego,项目名称:pyreco,代码行数:60,代码来源:allPythonContent.py
示例2: test_unencrypted
def test_unencrypted(self):
cell = Cell()
cell.ssid = 'SSID'
cell.encrypted = False
scheme = Scheme.for_cell('wlan0', 'test', cell)
self.assertEqual(scheme.options, {
'wireless-essid': 'SSID',
'wireless-channel': 'auto',
})
开发者ID:Mondego,项目名称:pyreco,代码行数:11,代码来源:allPythonContent.py
示例3: test_wep
def test_wep(self):
cell = Cell()
cell.ssid = 'SSID'
cell.encrypted = True
cell.encryption_type = 'wep'
scheme = Scheme.for_cell('wlan0', 'test', cell, 'passkey')
self.assertEqual(scheme.options, {
'wireless-essid': 'SSID',
'wireless-key': 'passkey',
})
开发者ID:Mondego,项目名称:pyreco,代码行数:12,代码来源:allPythonContent.py
示例4: test_wpa
def test_wpa(self):
cell = Cell()
cell.ssid = 'SSID'
cell.encrypted = True
cell.encryption_type = 'wpa'
scheme = Scheme.for_cell('wlan0', 'test', cell, 'passkey')
self.assertEqual(scheme.options, {
'wpa-ssid': 'SSID',
'wpa-psk': 'ea1548d4e8850c8d94c5ef9ed6fe483981b64c1436952cb1bf80c08a68cdc763',
'wireless-channel': 'auto',
})
开发者ID:Mondego,项目名称:pyreco,代码行数:13,代码来源:allPythonContent.py
示例5: update
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
开发者ID:NightyLive,项目名称:glances,代码行数:58,代码来源:glances_wifi.py
示例6: test_no_encryption
def test_no_encryption(self):
cell = Cell.from_string(IWLIST_SCAN_NO_ENCRYPTION)
self.assertFalse(cell.encrypted)
self.assertEqual(cell.ssid, 'My Wireless Network')
self.assertEqual(cell.signal, -51)
self.assertEqual(cell.quality, '59/70')
self.assertEqual(cell.frequency, '2.437 GHz')
self.assertEqual(cell.mode, 'Master')
self.assertEqual(cell.channel, 6)
开发者ID:DanLipsitt,项目名称:wifi,代码行数:9,代码来源:test_parsing.py
示例7: test_wpa2
def test_wpa2(self):
cell = Cell.from_string(IWLIST_SCAN_WPA2)
self.assertTrue(cell.encrypted)
self.assertEqual(cell.encryption_type, 'wpa2')
开发者ID:DanLipsitt,项目名称:wifi,代码行数:4,代码来源:test_parsing.py
示例8: test_alternative_iwlist_output
def test_alternative_iwlist_output(self):
# https://github.com/rockymeza/wifi/issues/12
cell = Cell.from_string(ALTERNATIVE_OUTPUT)
self.assertEqual(cell.quality, '78/100')
self.assertEqual(cell.signal, -92)
开发者ID:Develoman,项目名称:wifi,代码行数:5,代码来源:test_parsing.py
示例9: test_absolute_quality
def test_absolute_quality(self):
# https://github.com/rockymeza/wifi/pull/45
cell = Cell.from_string(ABSOLUTE_QUALITY)
self.assertEqual(cell.quality, '38/100')
self.assertEqual(cell.signal, -92)
开发者ID:Develoman,项目名称:wifi,代码行数:5,代码来源:test_parsing.py
示例10: test_wep
def test_wep(self):
cell = Cell.from_string(IWLIST_SCAN_WEP)
self.assertTrue(cell.encrypted)
self.assertEqual(cell.encryption_type, 'wep')
开发者ID:DanLipsitt,项目名称:wifi,代码行数:4,代码来源:test_parsing.py
示例11: test_list_index_error
def test_list_index_error(self):
# https://github.com/rockymeza/wifi/issues/42
cell = Cell.from_string(LIST_INDEX_ERROR)
开发者ID:Develoman,项目名称:wifi,代码行数:3,代码来源:test_parsing.py
示例12: test_frequency_no_channel_output
def test_frequency_no_channel_output(self):
# https://github.com/rockymeza/wifi/issues/39
cell = Cell.from_string(FREQUENCY_NO_CHANNEL_OUTPUT)
self.assertEqual(cell.channel, 149)
开发者ID:Develoman,项目名称:wifi,代码行数:4,代码来源:test_parsing.py
示例13: test_noname_cell
def test_noname_cell(self):
cell = Cell.from_string(NONAME_WIRELESS_NETWORK)
self.assertEqual(cell.ssid, '')
开发者ID:Develoman,项目名称:wifi,代码行数:3,代码来源:test_parsing.py
示例14: test_no_channel_output
def test_no_channel_output(self):
# https://github.com/rockymeza/wifi/issues/24
cell = Cell.from_string(NO_CHANNEL_OUTPUT)
self.assertEqual(cell.channel, 11)
开发者ID:Develoman,项目名称:wifi,代码行数:4,代码来源:test_parsing.py
示例15: test_signal_level_out_of_sixty
def test_signal_level_out_of_sixty(self):
cell = Cell.from_string(ALTERNATIVE_OUTPUT2)
self.assertEqual(cell.signal, -71)
开发者ID:Develoman,项目名称:wifi,代码行数:3,代码来源:test_parsing.py
示例16: tick
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",
#.........这里部分代码省略.........
开发者ID:opensourcehiker,项目名称:netscan,代码行数:101,代码来源:netscan.py
示例17: test_blank_ssid
def test_blank_ssid(self):
# https://github.com/rockymeza/wifi/issues/86
cell = Cell.from_string(NO_SSID_AT_ALL)
self.assertEqual(cell.ssid, None)
开发者ID:Evanito,项目名称:wifi,代码行数:4,代码来源:test_parsing.py
示例18: test_noise_data_present
def test_noise_data_present(self):
cell = Cell.from_string(LIST_INDEX_ERROR)
self.assertEqual(cell.noise, -92)
开发者ID:Evanito,项目名称:wifi,代码行数:3,代码来源:test_parsing.py
示例19: test_noise_no_data
def test_noise_no_data(self):
cell = Cell.from_string(IWLIST_SCAN_NO_ENCRYPTION)
self.assertEqual(cell.noise, None)
开发者ID:Evanito,项目名称:wifi,代码行数:3,代码来源:test_parsing.py
注:本文中的wifi.scan.Cell类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论