-
Notifications
You must be signed in to change notification settings - Fork 55
/
chanhopper.go
40 lines (36 loc) · 933 Bytes
/
chanhopper.go
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
package main
import (
"fmt"
"strings"
"time"
log "github.com/cihub/seelog"
)
func HopChannels(delay time.Duration) {
log.Infof("hoping channels with %s delay", delay)
// get list of channels
stdout, _ := RunCommand(10*time.Second, "iwlist "+wifiInterface+" freq")
channels := []string{}
for _, line := range strings.Split(stdout, "\n") {
if !strings.Contains(line, "Channel ") {
continue
}
fs := strings.Fields(line)
if len(fs) != 5 {
continue
}
if fs[2] != ":" {
continue
}
channels = append(channels, strings.Fields(line)[1])
}
log.Debugf("found %d channels: %+v", len(channels), channels)
for {
for _, channel := range channels {
log.Debugf("switching to channel %s", channel)
stdout, stderr := RunCommand(3*time.Second, fmt.Sprintf("iwconfig %s channel %s", wifiInterface, channel))
currentChannel = channel
log.Debug("output", stdout, stderr)
time.Sleep(delay)
}
}
}