Here's a Go (Golang) application that scrapes Wi-Fi quality metrics on Windows, using the netsh command-line tool, which is available by default on Windows systems.
This program will:
- Run the
netsh wlan show interfaces command
- Parse relevant Wi-Fi metrics like:
- SSID
- Signal quality (e.g., "80%")
- Radio type
- Transmit rate
- Receive rate
- BSSID
- Output them in a structured format (like JSON)
✅ Requirements
- Go installed (https://go.dev/dl/)
- Running on Windows (as it uses Windows-specific commands)
- Admin privileges not required for this specific command
📦 Go Application: wifi_scrape.go
package main
import (
"bufio"
"fmt"
"os/exec"
"regexp"
"strings"
"encoding/json"
)
// WiFiInterface represents parsed Wi-Fi interface data
type WiFiInterface struct {
SSID string `json:"ssid"`
BSSID string `json:"bssid"`
SignalQuality string `json:"signal_quality"`
RadioType string `json:"radio_type"`
TransmitRate string `json:"transmit_rate_mbps"`
ReceiveRate string `json:"receive_rate_mbps"`
}
func main() {
output, err := exec.Command("netsh", "wlan", "show", "interfaces").CombinedOutput()
if err != nil {
panic(fmt.Sprintf("Error running netsh command: %s\nOutput: %s", err, output))
}
result := parseWiFiInterfaces(string(output))
jsonData, _ := json.MarshalIndent(result, "", " ")
fmt.Println(string(jsonData))
}
func parseWiFiInterfaceValue(scanner *bufio.Scanner, key string) string {
for scanner.Scan() {
line := scanner.Text()
if strings.Contains(line, key) {
parts := strings.SplitN(line, ":", 2)
if len(parts) == 2 {
return strings.TrimSpace(parts[1])
}
}
}
return ""
}
func parseWiFiInterfaces(output string) []WiFiInterface {
var results []WiFiInterface
lines := strings.Split(output, "\n")
interfaceRegex := regexp.MustCompile(`\s*Name\s+:\s+(.+)$`)
var current WiFiInterface
for i := 0; i < len(lines); i++ {
line := lines[i]
// Detect new interface section
if match := interfaceRegex.FindStringSubmatch(line); match != nil {
current = WiFiInterface{} // Reset for new interface
continue
}
if strings.Contains(line, "SSID") && !strings.Contains(line, "BSSID") {
current.SSID = extractValue(line)
} else if strings.Contains(line, "BSSID") {
current.BSSID = extractValue(line)
} else if strings.Contains(line, "Signal") {
current.SignalQuality = extractValue(line)
} else if strings.Contains(line, "Radio type") {
current.RadioType = extractValue(line)
} else if strings.Contains(line, "Transmit rate") {
current.TransmitRate = extractValue(line)
} else if strings.Contains(line, "Receive rate") {
current.ReceiveRate = extractValue(line)
}
// If we've collected enough info, add to results
if current.SSID != "" && current.SignalQuality != "" {
results = append(results, current)
current = WiFiInterface{} // reset after adding
}
}
return results
}
func extractValue(line string) string {
parts := strings.SplitN(line, ":", 2)
if len(parts) == 2 {
return strings.TrimSpace(parts[1])
}
return ""
}
🧪 Sample Output
When you run this program, it may output something like:
[
{
"ssid": "MyHomeNetwork",
"bssid": "a1:b2:c3:d4:e5:f6",
"signal_quality": "75%",
"radio_type": "802.11ac",
"transmit_rate_mbps": "135 Mbps",
"receive_rate_mbps": "240 Mbps"
}
]
🚀 How to Run
- Save the code as
wifi_scrape.go
- Open a terminal in the same directory and run:
go run wifi_scrape.go
Or build an executable:
go build -o wifi_scrape.exe wifi_scrape.go
./wifi_scrape.exe
🛠️ Optional Enhancements
- Convert signal percentage into numeric value (e.g.,
"75%" → 75)
- Add error handling for cases where no Wi-Fi interfaces are found
- Export to CSV or send metrics to a monitoring system
- Cross-platform support (requires different tools for Linux/macOS)
Let me know if you want to extend this with logging, exporting to Prometheus, or turning it into a service!