zstdzgo.at/zstd/znet Index | Files

package znet

import "zgo.at/zstd/znet"

Package znet contains utilities for network communication.

Index

Functions

func PrivateIP

func PrivateIP(addr net.IP) bool

PrivateIP reports if this is a private non-public IP address.

func PrivateIPString

func PrivateIPString(ip string) bool

PrivateIPString reports if this is a private non-public IP address.

This will return true for anything that is not an IP address, such as "example.com" or "localhost".

func RemovePort

func RemovePort(host string) string

RemovePort removes the "port" part of an hostname.

This only works for "host:port", and not URLs. See net.SplitHostPort.

func SafeDialer

func SafeDialer(allowedNets []string, allowedPorts []int) *net.Dialer

SafeDialer is only alllowed to connect to the listed networks and ports on non-private addresses.

Any attempt to connect to e.g. "127.0.0.1" will return an error. This is intended for clients that should only connect to external resources from user input.

If the allowed lists are empty then "tcp4", "tcp6", "80", and "443" are used.

The Timeout and KeepAlive are set to 30 seconds.

Also see zhttputil.SafeTransport() and zhttputil.SafeClient().

Source Files

znet.go

Version
v0.0.0-20240930202209-a63c3335042a (latest)
Published
Sep 30, 2024
Platform
linux/amd64
Imports
7 packages
Last checked
2 days ago

Tools for package owners.