… | |
… | |
49 | $menu_idx += @menu if $menu_idx < 0; |
49 | $menu_idx += @menu if $menu_idx < 0; |
50 | $menu_idx -= @menu if $menu_idx >= @menu; |
50 | $menu_idx -= @menu if $menu_idx >= @menu; |
51 | |
51 | |
52 | erase; |
52 | erase; |
53 | |
53 | |
54 | my $data = $GPS->data; |
54 | my $data = $GPS ? $GPS->data : {}; |
55 | |
55 | |
56 | move 0, 0; |
56 | move 0, 0; |
57 | addstr $frame++ . ": " . localtime($data->{time}) . " $data->{lat} $data->{long} $data->{alt}m"; |
57 | addstr $frame++ . ": " . localtime($data->{time}) . " $data->{lat} $data->{long} $data->{alt}m"; |
58 | |
58 | |
59 | for my $idx (0 .. $#menu) { |
59 | for my $idx (0 .. $#menu) { |
… | |
… | |
158 | $s .= "(" . e2h($k) . " $v->{mode} '$v->{essid}') "; |
158 | $s .= "(" . e2h($k) . " $v->{mode} '$v->{essid}') "; |
159 | } |
159 | } |
160 | $s; |
160 | $s; |
161 | } |
161 | } |
162 | |
162 | |
|
|
163 | sub show_map { |
|
|
164 | my ($map, $w, $h) = @_; |
|
|
165 | |
|
|
166 | my @data = (("-" x $w) x $h); |
|
|
167 | |
|
|
168 | my ($x1, $y1, $x2, $y2) = (1e6, 1e6, 1e-6, 1e-6); |
|
|
169 | |
|
|
170 | while (my ($k, $v) = each %$map) { |
|
|
171 | my ($y, $x) = split /;/, $k; |
|
|
172 | $x1 = $x if $x1 > $x; |
|
|
173 | $x2 = $x if $x2 < $x; |
|
|
174 | $y1 = $y if $y1 > $y; |
|
|
175 | $y2 = $y if $y2 < $y; |
|
|
176 | } |
|
|
177 | |
|
|
178 | $x2 = ($w - 1) / (($x2 - $x1) || 1e-6); |
|
|
179 | $y2 = ($h - 1) / (($y2 - $y1) || 1e-6); |
|
|
180 | |
|
|
181 | while (my ($k, $v) = each %$map) { |
|
|
182 | my ($y, $x) = split /;/, $k; |
|
|
183 | |
|
|
184 | $y = ($y - $y1) * $y2; |
|
|
185 | $x = ($x - $x1) * $x2; |
|
|
186 | |
|
|
187 | substr $data[$y], $x, 1, "*"; |
|
|
188 | } |
|
|
189 | |
|
|
190 | for (@data) { |
|
|
191 | addstr $_ . "\n"; |
|
|
192 | } |
|
|
193 | } |
|
|
194 | |
163 | sub display_bss { |
195 | sub display_bss { |
164 | my $bss = shift; |
196 | my $bss = shift; |
165 | |
197 | |
166 | addstr "TS: $bss->{ts}\n"; |
198 | addstr "TS: $bss->{ts}\n"; |
167 | addstr "ARP/IP packets received: $bss->{arp}/$bss->{ip}\n"; |
199 | addstr "WEP/ARP/IP packets received: $bss->{wep}/$bss->{arp}/$bss->{ip}\n"; |
168 | |
200 | |
169 | addstr "\naccess points\n"; |
201 | addstr "\naccess points\n"; |
170 | |
202 | |
171 | while (my ($k, $v) = each %{$bss->{ap}}) { |
203 | while (my ($k, $v) = each %{$bss->{ap}}) { |
172 | addstr " " . e2h($k) . "\n"; |
204 | addstr " " . e2h($k) . "\n"; |
… | |
… | |
179 | addstr " " . e2h($k); |
211 | addstr " " . e2h($k); |
180 | while (my ($k, $v) = each %$v) { |
212 | while (my ($k, $v) = each %$v) { |
181 | addstr " " . (inet_ntoa $k) . "($v)"; |
213 | addstr " " . (inet_ntoa $k) . "($v)"; |
182 | } |
214 | } |
183 | addstr "\n"; |
215 | addstr "\n"; |
|
|
216 | } |
|
|
217 | |
|
|
218 | if ($bss->{gps}) { |
|
|
219 | addstr "\nmap\n"; |
|
|
220 | show_map $bss->{gps}, 40, 20; |
184 | } |
221 | } |
185 | } |
222 | } |
186 | |
223 | |
187 | sub menu_bss_list { |
224 | sub menu_bss_list { |
188 | my @menu; |
225 | my @menu; |
… | |
… | |
198 | }; |
235 | }; |
199 | } |
236 | } |
200 | } |
237 | } |
201 | |
238 | |
202 | sub activity { |
239 | sub activity { |
|
|
240 | if ($GPS) { |
|
|
241 | my $data = $GPS->data; |
|
|
242 | $db->{$_[0]}{gps}{"$data->{lat};$data->{long}"} = 1; |
|
|
243 | } |
203 | $db->{$_[0]}->{ts} = time; |
244 | $db->{$_[0]}->{ts} = time; |
204 | #print "activity ", e2h $_[0]; print "\n"; |
|
|
205 | $refresh->start; |
245 | $refresh->start; |
206 | } |
246 | } |
207 | |
247 | |
208 | sub reg_ip { |
248 | sub reg_ip { |
209 | my ($bssid, $ip, $ether) = @_; |
249 | my ($bssid, $ip, $ether) = @_; |
… | |
… | |
237 | |
277 | |
238 | activity $a3; |
278 | activity $a3; |
239 | } elsif ($fc1 == 0x08) { |
279 | } elsif ($fc1 == 0x08) { |
240 | my $bssid = ($a3, $a2, $a1)[$fc2 & 3]; |
280 | my $bssid = ($a3, $a2, $a1)[$fc2 & 3]; |
241 | |
281 | |
|
|
282 | if ($fc2 & 0x40) { |
|
|
283 | $db->{$bssid}{wep}++; |
|
|
284 | } else { |
242 | my ($llc, $et, $pkt) = unpack "a6 n a*", $pkt; |
285 | my ($llc, $et, $pkt) = unpack "a6 n a*", $pkt; |
243 | if ($llc eq "\xaa\xaa\x03\x00\x00\x00") { # SNAP/UI/ENCAP_ETHER |
286 | if ($llc eq "\xaa\xaa\x03\x00\x00\x00") { # SNAP/UI/ENCAP_ETHER |
244 | if ($et == 0x0800) { |
287 | if ($et == 0x0800) { |
245 | my ($vhl, $tos, $len, $id, $off, $ttl, $prot, $sum, $src, $dst, $pkt) |
288 | my ($vhl, $tos, $len, $id, $off, $ttl, $prot, $sum, $src, $dst, $pkt) |
246 | = unpack "C C n n n C C n a4 a4 a*", $pkt; |
289 | = unpack "C C n n n C C n a4 a4 a*", $pkt; |
247 | if ($vhl & 0x40 == 0x40) { |
290 | if ($vhl & 0x40 == 0x40) { |
248 | $db->{$bssid}{ip}++; |
291 | $db->{$bssid}{ip}++; |
249 | reg_ip $bssid, $src, $a2; |
292 | reg_ip $bssid, $src, $a2; |
250 | reg_ip $bssid, $dst, $a1; |
293 | reg_ip $bssid, $dst, $a1; |
251 | 0 && |
294 | 0 && |
252 | printf "IP: %02x %02x %04x %04x: %s %s> %s %s %02x \n", |
295 | printf "IP: %02x %02x %04x %04x: %s %s> %s %s %02x \n", |
253 | $fc1, $fc2, $sid, $sc, |
296 | $fc1, $fc2, $sid, $sc, |
254 | (unpack "H*", $a2), (inet_ntoa $src), |
297 | (unpack "H*", $a2), (inet_ntoa $src), |
255 | (unpack "H*", $a1), (inet_ntoa $dst), |
298 | (unpack "H*", $a1), (inet_ntoa $dst), |
256 | $prot; |
299 | $prot; |
|
|
300 | } |
|
|
301 | } elsif ($et == 0x0806) { |
|
|
302 | my ($hrd, $pro, $hln, $pln, $op, $src_hw, $src, $dst_hw, $dst) |
|
|
303 | = unpack "n n C C n a6 a4 a6 a4", $pkt; |
|
|
304 | if ($hrd == 1 and $hln == 6 and $pln == 4) { |
|
|
305 | reg_ip $bssid, $src, $src_hw; |
|
|
306 | reg_ip $bssid, $dst, $dst_hw if $op != 1; |
|
|
307 | $db->{$bssid}{arp}++; |
|
|
308 | 0 && |
|
|
309 | printf "ARP: %04x> %s %s : %s %s\n", |
|
|
310 | $op, |
|
|
311 | (unpack "H*", $src_hw), (inet_ntoa $src), |
|
|
312 | (unpack "H*", $dst_hw), (inet_ntoa $dst); |
|
|
313 | } |
257 | } |
314 | } |
258 | } elsif ($et == 0x0806) { |
315 | } else { |
259 | my ($hrd, $pro, $hln, $pln, $op, $src_hw, $src, $dst_hw, $dst) |
|
|
260 | = unpack "n n C C n a6 a4 a6 a4", $pkt; |
|
|
261 | if ($hrd == 1 and $hln == 6 and $pln == 4) { |
|
|
262 | reg_ip $bssid, $src, $src_hw; |
|
|
263 | reg_ip $bssid, $dst, $dst_hw if $op != 1; |
|
|
264 | $db->{$bssid}{arp}++; |
|
|
265 | 0 && |
316 | 0 && |
266 | printf "ARP: %04x> %s %s : %s %s\n", |
317 | printf "?? %02x %02x %04x %04x: %s.%s \n", $fc1, $fc2, $sid, $sc, (unpack "H*", $llc), unpack "H*", $pkt; |
267 | $op, |
|
|
268 | (unpack "H*", $src_hw), (inet_ntoa $src), |
|
|
269 | (unpack "H*", $dst_hw), (inet_ntoa $dst); |
|
|
270 | } |
|
|
271 | } |
318 | } |
272 | } else { |
|
|
273 | 0 && |
|
|
274 | printf "?? %02x %02x %04x %04x: %s.%s \n", $fc1, $fc2, $sid, $sc, (unpack "H*", $llc), unpack "H*", $pkt; |
|
|
275 | } |
319 | } |
276 | } elsif ($fc1 != 0x40 and $fc1 != 0x10 and $fc1 != 0x00 and $fc1 != 0xb0) { |
320 | } elsif ($fc1 != 0x40 and $fc1 != 0x10 and $fc1 != 0x00 and $fc1 != 0xb0) { |
277 | 0 && |
321 | 0 && |
278 | printf "%02x %02x %04x %04x: %s \n", $fc1, $fc2, $sid, $sc, unpack "H*", $pkt; |
322 | printf "%02x %02x %04x %04x: %s \n", $fc1, $fc2, $sid, $sc, unpack "H*", $pkt; |
279 | } |
323 | } |