-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathtest.py
More file actions
122 lines (113 loc) · 4.08 KB
/
test.py
File metadata and controls
122 lines (113 loc) · 4.08 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
# Python 2
# python2 setup.py build
# python2 iwlist.py wlp59s0 channel
# pip2 install python-wifi==0.6.1
# python2 setup.py sdist --force-manifest --formats=bztar
# pip2 install dist/python-wifi-0.6.2.tar.bz2
# pip2 uninstall python-wifi
# Python 3
# python3 setup.py sdist --force-manifest --formats=bztar
# python3 iwlist.py wlp59s0 channel
# python3 setup.py build
# pip3 install dist/python-wifi-0.6.2.tar.bz2
# pip3 uninstall python-wifi
import pythonwifi.flags
from pythonwifi.iwlibs import Wireless, Iwscan
wifi = Wireless('wlp59s0')
print(wifi.getEssid())
print(wifi.getMode())
keys = wifi.getKeys()
print(wifi.getPowermanagement())
print(wifi.getQualityAvg())
print(wifi.getWirelessName())
print(wifi.getAPaddr())
print(wifi.getBitrate())
print(wifi.getChannelInfo())
print(wifi.getEncryption())
print(wifi.getFragmentation())
print(wifi.getFrequency())
print(wifi.getQualityMax())
print(wifi.getRetrylimit())
print(wifi.getRTS())
#print(wifi.getSensitivity())
print(wifi.getStatistics())
print(wifi.getTXPower())
print(wifi.getWirelessName())
for key in keys:
print(key)
scan = wifi.scan()
a = 4
(num_channels, frequencies) = wifi.getChannelInfo()
index = 1
for ap in scan.aplist:
print(" Cell %02d - Address: %s" % (index, ap.bssid))
print(" ESSID:\"%s\"" % (ap.essid, ))
print(" Mode:%s" % (ap.mode, ))
print(" Frequency:%s (Channel %d)" % \
(wifi._formatFrequency(ap.frequency.getFrequency()),
frequencies.index(wifi._formatFrequency(
ap.frequency.getFrequency())) + 1))
if (ap.quality.updated & \
pythonwifi.flags.IW_QUAL_QUAL_UPDATED):
quality_updated = "="
else:
quality_updated = ":"
if (ap.quality.updated & \
pythonwifi.flags.IW_QUAL_LEVEL_UPDATED):
signal_updated = "="
else:
signal_updated = ":"
if (ap.quality.updated & \
pythonwifi.flags.IW_QUAL_NOISE_UPDATED):
noise_updated = "="
else:
noise_updated = ":"
print(" " + \
"Quality%c%s/%s Signal level%c%s/%s Noise level%c%s/%s" % \
(quality_updated,
ap.quality.quality,
wifi.getQualityMax().quality,
signal_updated,
ap.quality.getSignallevel(),
"100",
noise_updated,
ap.quality.getNoiselevel(),
"100"))
# This code on encryption keys is very fragile
key_status = ""
if (ap.encode.flags & pythonwifi.flags.IW_ENCODE_DISABLED):
key_status = "off"
else:
if (ap.encode.flags & pythonwifi.flags.IW_ENCODE_NOKEY):
if (ap.encode.length <= 0):
key_status = "on"
print(" Encryption key:%s" % (key_status, ))
if len(ap.rate) > 0:
for rate_list in ap.rate:
# calc how many full lines of bitrates
rate_lines = len(rate_list) // 5
# calc how many bitrates on last line
rate_remainder = len(rate_list) % 5
line = 0
# first line should start with a label
rate_line = " Bit Rates:"
while line < rate_lines:
# print full lines
if line > 0:
# non-first lines should start *very* indented
rate_line = " "
rate_line = rate_line + "%s; %s; %s; %s; %s" % \
tuple(wifi._formatBitrate(x) for x in
rate_list[line * 5:(line * 5) + 5])
line = line + 1
print(rate_line)
if line > 0:
# non-first lines should start *very* indented
rate_line = " "
# print non-full line
print(rate_line + "%s; "*(rate_remainder - 1) % \
tuple(wifi._formatBitrate(x) for x in
rate_list[line * 5:line * 5 + rate_remainder - 1]) + \
"%s" % (wifi._formatBitrate(
rate_list[line * 5 + rate_remainder - 1])))
index = index + 1