Created
January 14, 2019 21:26
-
-
Save danesparza/de38abcaade3fac796d6a86d2185bf6e to your computer and use it in GitHub Desktop.
Command execution (with pipes) in Go / golang
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import ( | |
"log" | |
"os/exec" | |
) | |
func main() { | |
// First, query the OS to get a list of Wifi AP SSIDs | |
cmd := "sudo iw dev wlan0 scan | grep SSID" | |
out, err := exec.Command("bash", "-c", cmd).Output() | |
if err != nil { | |
log.Fatalf("Error: %v", err) | |
} | |
// Debug: | |
log.Printf("The data is:\n%s\n", out) | |
/** | |
Example output: | |
SSID: Chupacabra | |
SSID: Princess_Wifi | |
SSID: Chupacabra | |
SSID: Nahual | |
SSID: | |
SSID: | |
SSID: Nahual | |
SSID: Princess_Wifi | |
SSID: ATT7M2Y587 | |
SSID: MarksPlace | |
SSID: ATT34AH43d | |
SSID: HOME-F862 | |
SSID: Default-guest | |
SSID: ATT0500 | |
SSID: Zapeda | |
Extended capabilities: TFS, WNM-Sleep Mode, TIM Broadcast, BSS Transition, SSID List, 6 | |
SSID: xfinitywifi | |
*/ | |
// Next, parse this list | |
// - No blank SSID's | |
// - No extended capability information | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment