netutil

package
v0.7.4 Latest Latest
Warning

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

Go to latest
Published: Mar 12, 2026 License: MIT Imports: 3 Imported by: 0

README

Net Utils

  • provide some network utils. eg: InternalIPv4
  • sub package:
    • httpctypes - provide some commonly http content types.
    • httpheader - provide some commonly http header names.
    • httpreq - provide some http request utils

Install

go get github.com/gookit/goutil/netutil

Go docs

Usage

import "github.com/gookit/goutil/netutil"
// Get internal IPv4 address
netutil.InternalIPv4()

Testings

go test -v ./netutil/...

Test limit by regexp:

go test -v -run ^TestSetByKeys ./netutil/...

Documentation

Overview

Package netutil provide some network util functions.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AllLocalIPv4 added in v0.7.4

func AllLocalIPv4() ([]string, error)

AllLocalIPv4 Get all non-loop IPv4 addresses. 获取所有非回环 IPv4 地址

func AllMacAddrs added in v0.7.4

func AllMacAddrs() ([]string, error)

AllMacAddrs get all mac addresses

func FirstMacAddr added in v0.7.4

func FirstMacAddr() (string, error)

FirstMacAddr 获取第一个非lo网卡的MAC地址

func FreePort added in v0.6.13

func FreePort() (port int, err error)

FreePort returns a free port.

func GetLocalIPs added in v0.6.10

func GetLocalIPs() (ips []string)

GetLocalIPs get local IPs(ipv4+ipv6), will panic on error.

func HostIP added in v0.6.13

func HostIP() ([]string, error)

HostIP returns the IP addresses of the local hostname.

func IPv4 added in v0.6.13

func IPv4() string

IPv4 get local first internal IPv4 addr.

func IPv6 added in v0.6.13

func IPv6() string

IPv6 get local first internal IPv6 addr

func IncrIP added in v0.7.3

func IncrIP(ip net.IP)

IncrIP 将IP地址递增1 eg: 192.168.1.1 -> 192.168.1.2

func InternalIP

func InternalIP() string

InternalIP get local first internal IP v4/v6 addr.

func InternalIPv4 added in v0.5.0

func InternalIPv4() string

InternalIPv4 get internal IPv4 for host.

func InternalIPv6 added in v0.5.0

func InternalIPv6() string

InternalIPv6 get first internal IPv6 addr

func MustIPv4 added in v0.7.4

func MustIPv4() (ip string)

MustIPv4 get first internal IP v4 addr, will panic on error or not found.

Types

This section is empty.

Directories

Path Synopsis
Package httpctype list some common http content-type
Package httpctype list some common http content-type
Package httpheader provides some common http header names.
Package httpheader provides some common http header names.
Package httpreq provide an simple http requester and some useful util functions.
Package httpreq provide an simple http requester and some useful util functions.

Jump to

Keyboard shortcuts

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