Speedtest Checker
A simple Go program to check internet speed using the Speedtest by Ookla API.
The main idea is to create a binary for BSD that can run inside the PFSense, but then , this can be compiled to run anywhere...
Find source code and release here:
Prerequisites
Go: Ensure you have Go installed on your development machine.
speedtest-go Library: Clone the library from GitHub.
git clone https://github.com/showwin/speedtest-go.git cd speedtest-goCreate a New Go Project:
mkdir speedtest-checker cd speedtest-checker go mod init speedtest-checker
Installation
Install the Library:
go get github.com/showwin/speedtest-go/speedtestWrite the Code: Implement the logic to use the
speedtest-golibrary to check internet speed.Create a file named
main.goin your project directory and add the following code:package main import ( "fmt" "github.com/showwin/speedtest-go/speedtest" ) func main() { var speedtestClient = speedtest.New() // Use a proxy for the speedtest. eg: socks://127.0.0.1:7890 // speedtest.WithUserConfig(&speedtest.UserConfig{Proxy: "socks://127.0.0.1:7890"})(speedtestClient) // Select a network card as the data interface. // speedtest.WithUserConfig(&speedtest.UserConfig{Source: "192.168.1.101"})(speedtestClient) // Get user's network information // user, _ := speedtestClient.FetchUserInfo() // Get a list of servers near a specified location // user.SetLocationByCity("Tokyo") // user.SetLocation("Osaka", 34.6952, 135.5006) // Search server using serverID. // eg: fetch server with ID 28910. // speedtest.ErrServerNotFound will be returned if the server cannot be found. // server, err := speedtest.FetchServerByID("28910") serverList, _ := speedtestClient.FetchServers() targets, _ := serverList.FindServer([]int{}) for _, s := range targets { // Please make sure your host can access this test server, // otherwise you will get an error. // It is recommended to replace a server at this time s.PingTest(nil) s.DownloadTest() s.UploadTest() // Note: The unit of s.DLSpeed, s.ULSpeed is bytes per second, this is a float64. fmt.Printf("Latency: %s, Download: %.2f Mbps, Upload: %.2f Mbps\n", s.Latency, s.DLSpeed/1000000, s.ULSpeed/1000000) s.Context.Reset() // reset counter } }
Cross-Compiling for pfSense
To compile the program for pfSense (FreeBSD), follow these steps:
Set Environment Variables:
export GOOS=freebsd export GOARCH=amd64Compile the Program:
go build -o speedtest-bsd main.go
Running on pfSense
Transfer the compiled binary to your pfSense machine and run it.
- Transfer the Binary: Use
scpor any other method to transferspeedtest-bsdto your pfSense machine. - Run the Binary:
./speedtest-bsd
Troubleshooting
If you still encounter issues, here are a few troubleshooting steps:
Check Go Version: Ensure you are using a compatible version of Go for cross-compilation.
go versionVerify Binary Format: Ensure the binary is in the correct format for FreeBSD.
Permissions: Make sure the binary has execute permissions on your pfSense machine.
chmod +x speedtest-bsdDependencies: Ensure all dependencies are correctly installed and available on your pfSense system.


