netcheck

package
v0.7.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jun 25, 2026 License: MIT Imports: 4 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package netcheck reports whether the machine currently has working internet access. It uses the standard captive-portal "generate_204" probes (a full DNS+TCP+HTTP check) with a short timeout, and a raw TCP dial as a fallback.

Index

Constants

View Source
const DefaultTCPAddr = "1.1.1.1:443"

DefaultTCPAddr is dialed if every HTTP probe fails (e.g. HTTP egress blocked but raw TCP works). 1.1.1.1:443 is Cloudflare's anycast resolver.

Variables

View Source
var DefaultEndpoints = []string{
	"http://cp.cloudflare.com/generate_204",
	"http://connectivitycheck.gstatic.com/generate_204",
}

DefaultEndpoints are well-known endpoints that return HTTP 204 No Content when the network is unrestricted (used by OS captive-portal detection).

Functions

func Online

func Online(ctx context.Context) bool

Online is a package-level convenience using default settings.

Types

type Checker

type Checker struct {
	Endpoints []string
	TCPAddr   string
	Timeout   time.Duration
	Client    *http.Client
}

Checker performs connectivity checks. The zero value is not usable; call New.

func New

func New() *Checker

New returns a Checker with sensible defaults (~3s timeout, no redirects).

func (*Checker) Online

func (c *Checker) Online(ctx context.Context) bool

Online reports whether any probe succeeds. It is best-effort: a single success returns true; all failures (or a cancelled ctx) return false.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL