Documentation ¶
Index ¶
- Constants
- Variables
- func Gateways() []net.IP
- func GetApproximateInternetLocation() (net.IP, error)
- func GetAssignedAddresses() (ipv4 []net.IP, ipv6 []net.IP, err error)
- func GetAssignedGlobalAddresses() (ipv4 []net.IP, ipv6 []net.IP, err error)
- func GetNetworkChangedFlag() *utils.Flag
- func IsConnectivityDomain(domain string) bool
- func IsMyIP(ip net.IP) (yes bool, err error)
- func ListenToICMP() (packets chan packet.Packet, done func())
- func Online() bool
- func ReportFailedConnection()
- func ReportSuccessfulConnection()
- func SetInternetLocation(ip net.IP, source DeviceLocationSource) (ok bool)
- func SetLocalAddrFactory(laf func(network string) net.Addr)
- func SubmitPacketToICMPListener(pkt packet.Packet) (submitted bool)
- type CaptivePortal
- type DeviceLocation
- type DeviceLocationSource
- type DeviceLocations
- type Nameserver
- type OnlineStatus
Constants ¶
const ( NetworkChangedEvent = "network changed" OnlineStatusChangedEvent = "online status changed" )
Event Names
Variables ¶
var ( PortalTestIP = net.IPv4(192, 0, 2, 1) PortalTestURL = fmt.Sprintf("http://%s/", PortalTestIP) DNSTestDomain = "one.one.one.one." DNSTestExpectedIP = net.IPv4(1, 1, 1, 1) // SpecialCaptivePortalDomain is the domain name used to point to the detected captive portal IP // or the captive portal test IP. The default value should be overridden by the resolver package, // which defines the custom internal domain name to use. SpecialCaptivePortalDomain = "captiveportal.invalid." // ConnectivityDomains holds all connectivity domains. This slice must not be modified. ConnectivityDomains = []string{ SpecialCaptivePortalDomain, "one.one.one.one.", "dns.msftncsi.com.", "msftncsi.com.", "www.msftncsi.com.", "microsoftconnecttest.com.", "www.microsoftconnecttest.com.", "ipv6.microsoftconnecttest.com.", "captive.apple.com.", "connectivity-check.ubuntu.com.", "nmcheck.gnome.org.", "network-test.debian.org.", "204.pop-os.org", "connectivitycheck.gstatic.com.", "neverssl.com.", "detectportal.firefox.com.", } )
Online Status and Resolver
Functions ¶
func GetApproximateInternetLocation ¶
DEPRECATED: Please use GetInternetLocation instead.
func GetAssignedAddresses ¶
GetAssignedAddresses returns the assigned IPv4 and IPv6 addresses of the host.
func GetAssignedGlobalAddresses ¶
GetAssignedGlobalAddresses returns the assigned global IPv4 and IPv6 addresses of the host.
func GetNetworkChangedFlag ¶ added in v0.6.9
func IsConnectivityDomain ¶ added in v0.4.12
IsConnectivityDomain checks whether the given domain (fqdn) is used for any connectivity related network connections and should always be resolved using the network assigned DNS server.
func IsMyIP ¶ added in v0.5.2
IsMyIP returns whether the given unicast IP is currently configured on the local host. Broadcast or multicast addresses will never match, even if valid in in use.
func ListenToICMP ¶ added in v0.6.9
ListenToICMP returns a new channel for listenting to icmp packets. Please note that any icmp packet will be passed and filtering must be done on the side of the caller. The caller must call the returned done function when done with the listener.
func Online ¶
func Online() bool
Online returns true if online status is either SemiOnline or Online.
func ReportFailedConnection ¶
func ReportFailedConnection()
ReportFailedConnection hints the online status monitoring system that a connection attempt has failed. This function has extremely low overhead and may be called as much as wanted.
func ReportSuccessfulConnection ¶
func ReportSuccessfulConnection()
ReportSuccessfulConnection hints the online status monitoring system that a connection attempt was successful.
func SetInternetLocation ¶ added in v0.6.9
func SetInternetLocation(ip net.IP, source DeviceLocationSource) (ok bool)
func SetLocalAddrFactory ¶
SetLocalAddrFactory supplies the environment package with a function to get permitted local addresses for connections.
func SubmitPacketToICMPListener ¶ added in v0.6.9
SubmitPacketToICMPListener checks if an ICMP packet should be submitted to the listener. If so, it is submitted right away. The function returns whether or not the packet should be submitted, not if it was successful.
Types ¶
type CaptivePortal ¶ added in v0.4.12
CaptivePortal holds information about a detected captive portal.
func GetCaptivePortal ¶ added in v0.4.12
func GetCaptivePortal() *CaptivePortal
GetCaptivePortal returns the current captive portal. The returned struct must not be edited.
type DeviceLocation ¶ added in v0.6.9
type DeviceLocation struct { IP net.IP IPVersion packet.IPVersion Location *geoip.Location Source DeviceLocationSource SourceAccuracy int }
DeviceLocation represents a single IP and metadata. It must not be changed once created.
func (*DeviceLocation) IsMoreAccurateThan ¶ added in v0.6.9
func (dl *DeviceLocation) IsMoreAccurateThan(other *DeviceLocation) bool
IsMoreAccurateThan checks if the device location is more accurate than the given one.
func (*DeviceLocation) LocationOrNil ¶ added in v0.7.0
func (dl *DeviceLocation) LocationOrNil() *geoip.Location
func (*DeviceLocation) String ¶ added in v0.7.0
func (dl *DeviceLocation) String() string
type DeviceLocationSource ¶ added in v0.6.9
type DeviceLocationSource string
const ( SourceInterface DeviceLocationSource = "interface" SourcePeer DeviceLocationSource = "peer" SourceUPNP DeviceLocationSource = "upnp" SourceTraceroute DeviceLocationSource = "traceroute" SourceOther DeviceLocationSource = "other" )
func (DeviceLocationSource) Accuracy ¶ added in v0.6.9
func (dls DeviceLocationSource) Accuracy() int
type DeviceLocations ¶ added in v0.6.9
type DeviceLocations struct {
All []*DeviceLocation
}
func GetInternetLocation ¶ added in v0.6.9
func GetInternetLocation() (deviceLocations *DeviceLocations, ok bool)
func (*DeviceLocations) Best ¶ added in v0.6.9
func (dl *DeviceLocations) Best() *DeviceLocation
func (*DeviceLocations) BestV4 ¶ added in v0.7.0
func (dl *DeviceLocations) BestV4() *DeviceLocation
func (*DeviceLocations) BestV6 ¶ added in v0.7.0
func (dl *DeviceLocations) BestV6() *DeviceLocation
type Nameserver ¶
Nameserver describes a system assigned namserver.
func Nameservers ¶
func Nameservers() []Nameserver
Nameservers returns the currently active nameservers.
type OnlineStatus ¶
type OnlineStatus uint8
OnlineStatus represent a state of connectivity to the Internet.
const ( StatusUnknown OnlineStatus = 0 StatusOffline OnlineStatus = 1 StatusLimited OnlineStatus = 2 // local network only StatusPortal OnlineStatus = 3 // there seems to be an internet connection, but we are being intercepted, possibly by a captive portal StatusSemiOnline OnlineStatus = 4 // we seem to online, but without full connectivity StatusOnline OnlineStatus = 5 )
Online Status Values
func CheckAndGetOnlineStatus ¶
func CheckAndGetOnlineStatus() OnlineStatus
CheckAndGetOnlineStatus triggers a new online status check and returns the result
func GetOnlineStatus ¶
func GetOnlineStatus() OnlineStatus
GetOnlineStatus returns the current online stats.
func (OnlineStatus) String ¶
func (os OnlineStatus) String() string