PFSense Speed Test

PFSense Speed Test

spectroman
spectroman
4 views

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:

Repo
Release

Prerequisites

  1. Go: Ensure you have Go installed on your development machine.

  2. speedtest-go Library: Clone the library from GitHub.

    git clone https://github.com/showwin/speedtest-go.git
    cd speedtest-go
  3. Create a New Go Project:

    mkdir speedtest-checker
    cd speedtest-checker
    go mod init speedtest-checker

Installation

  1. Install the Library:

    go get github.com/showwin/speedtest-go/speedtest
  2. Write the Code: Implement the logic to use the speedtest-go library to check internet speed.

    Create a file named main.go in 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:

  1. Set Environment Variables:

    export GOOS=freebsd
    export GOARCH=amd64
  2. Compile the Program:

    go build -o speedtest-bsd main.go

Running on pfSense

Transfer the compiled binary to your pfSense machine and run it.

  1. Transfer the Binary: Use scp or any other method to transfer speedtest-bsd to your pfSense machine.
  2. Run the Binary:
    ./speedtest-bsd

Troubleshooting

If you still encounter issues, here are a few troubleshooting steps:

  1. Check Go Version: Ensure you are using a compatible version of Go for cross-compilation.

    go version
  2. Verify Binary Format: Ensure the binary is in the correct format for FreeBSD.

  3. Permissions: Make sure the binary has execute permissions on your pfSense machine.

    chmod +x speedtest-bsd
  4. Dependencies: Ensure all dependencies are correctly installed and available on your pfSense system.

Related Posts

Custom Fiber Home Link with PFSense
linuxpfsenseinternet

Custom Fiber Home Link with PFSense

To avoid using KPN or other provider router, you can always rely on PFSense and dedicated hardware to make it yourself!

3/27/2026Read More →