MCPcopy
hub / github.com/bettercap/bettercap / SetInterfaceChannel

Function SetInterfaceChannel

network/net_linux.go:35–66  ·  view source on GitHub ↗
(iface string, channel int)

Source from the content-addressed store, hash-verified

33}
34
35func SetInterfaceChannel(iface string, channel int) error {
36 curr := GetInterfaceChannel(iface)
37 // the interface is already on this channel
38 if curr == channel {
39 return nil
40 }
41
42 if core.HasBinary("iw") {
43 // Debug("SetInterfaceChannel(%s, %d) iw based", iface, channel)
44 // out, err := core.Exec("iw", []string{"dev", iface, "set", "channel", fmt.Sprintf("%d", channel)})
45 out, err := core.Exec("iw", []string{"dev", iface, "set", "freq", fmt.Sprintf("%d", Dot11Chan2Freq(channel))})
46
47 if err != nil {
48 return fmt.Errorf("iw: out=%s err=%s", out, err)
49 } else if out != "" {
50 return fmt.Errorf("Unexpected output while setting interface %s to channel %d: %s", iface, channel, out)
51 }
52 } else if core.HasBinary("iwconfig") {
53 // Debug("SetInterfaceChannel(%s, %d) iwconfig based")
54 out, err := core.Exec("iwconfig", []string{iface, "channel", fmt.Sprintf("%d", channel)})
55 if err != nil {
56 return fmt.Errorf("iwconfig: out=%s err=%s", out, err)
57 } else if out != "" {
58 return fmt.Errorf("Unexpected output while setting interface %s to channel %d: %s", iface, channel, out)
59 }
60 } else {
61 return fmt.Errorf("no iw or iwconfig binaries found in $PATH")
62 }
63
64 SetInterfaceCurrentChannel(iface, channel)
65 return nil
66}
67
68var iwlistFreqParser = regexp.MustCompile(`^\s+Channel.([0-9]+)\s+:\s+([0-9\.]+)\s+GHz.*$`)
69

Callers 2

hopUnlockedMethod · 0.92
ConfigureMethod · 0.92

Calls 5

HasBinaryFunction · 0.92
ExecFunction · 0.92
GetInterfaceChannelFunction · 0.85
Dot11Chan2FreqFunction · 0.85

Tested by

no test coverage detected