-
Notifications
You must be signed in to change notification settings - Fork 0
/
essidtop.rb
executable file
·77 lines (60 loc) · 1.37 KB
/
essidtop.rb
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
#!/usr/bin/ruby
def get_stats(card)
vals = {}
cell = nil
current = {
:mac => '??:??:??:??:??:??',
:essid => 'Unknown',
:channel => '-1',
:snratio => 0,
:key => '???'
}
%x[/usr/sbin/iwlist #{card} scan].each_line do |ln|
ln.chomp!
ln.gsub!(/^\s+/, '')
ln.gsub!(/\s+$/, '')
case ln
when /^Cell ([[:digit:]]+) - Address: ([A-Fa-f[:digit:]:]+)$/ then
unless (cell.nil?) then
vals[cell] = current
current = {
:mac => '??:??:??:??:??:??',
:essid => 'Unknown',
:channel => '-1',
:snratio => 0,
:key => '???'
}
end
cell = $1
current[:mac] = $2
when /^ESSID:"(.*)"$/ then
current[:essid] = $1
when /^Channel:([[:digit:]]+)$/ then
current[:channel] = $1
when /^Quality=([[:digit:]]+)\/([[:digit:]]+)\s/ then
current[:snratio] = (100 * ($1.to_f / $2.to_f)).to_i
when /^Encryption key:(on|off)/ then
current[:key] = $1
else
#puts "Unmatched: '#{ln}'"
end
end
unless (cell.nil?) then
vals[cell] = current
end
vals
end
card = ARGV[0]
loop do
stats = get_stats card
if ($stdout.isatty) then
printf "\e[H\e[2J"
end
# foreach key in stats
printf "Cell %-17s Ch SN Enc ESSID\n" % 'Mac'
stats.each do |k,v|
# print out line
printf "%-4s %-17s %02d %02d %3s %s\n" % [k, v[:mac], v[:channel].to_i,v[:snratio], v[:key], v[:essid]]
end
sleep 10
end