Skip to content

Commit

Permalink
Fix for #42 and #62, adding iwlist for when iw is not available
Browse files Browse the repository at this point in the history
  • Loading branch information
schollz committed Apr 21, 2016
1 parent dedb794 commit b2e3f67
Show file tree
Hide file tree
Showing 3 changed files with 419 additions and 4 deletions.
11 changes: 11 additions & 0 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ var format2 = logging.MustStringFormatter(

var verbose = true
var errorsInARow = 0
var hasIw = true

func getInput(prompt string) string {
reader := bufio.NewReader(os.Stdin)
Expand Down Expand Up @@ -175,6 +176,16 @@ func main() {
}
app.Run(os.Args)

// Check, if linux, if user has iw or iwlist
if runtime.GOOS == "linux" {
command := "/sbin/iw dev wlan0 scan -u"
out, _ := exec.Command(strings.Split(command, " ")[0], strings.Split(command, " ")[1:]...).Output()
if strings.Contains(string(out), "not found") {
hasIw = false
log.Notice("/sbin/iw not found, defaulting to /sbin/iwlist")
}
}

// Print the current parameters
log.Notice("You can see fewer messages by adding --nodebug")
log.Notice("User: " + f.Username)
Expand Down
16 changes: 12 additions & 4 deletions os_configuration.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,10 +47,18 @@ func populateConfigurations(wlanInterface string) {
ScanConfig: ScanParsingConfig{darwinFindMac, darwinFindRssi},
}

linuxCommand := "/sbin/iw dev " + wlanInterface + " scan -u"
osConfigurations["linux"] = OSConfig{
WifiScanCommand: linuxCommand,
ScanConfig: ScanParsingConfig{linuxFindMac, linuxFindRssi},
if hasIw {
linuxCommand := "/sbin/iw dev " + wlanInterface + " scan -u"
osConfigurations["linux"] = OSConfig{
WifiScanCommand: linuxCommand,
ScanConfig: ScanParsingConfig{linuxFindMac, linuxFindRssi},
}
} else {
linuxCommand := "/sbin/iwlist " + wlanInterface + " scan"
osConfigurations["linux"] = OSConfig{
WifiScanCommand: linuxCommand,
ScanConfig: ScanParsingConfig{linuxFindMac, linuxFindRssiIwList},
}
}

osConfigurations["windows"] = OSConfig{
Expand Down
Loading

0 comments on commit b2e3f67

Please sign in to comment.