xip

package
v0.25.15 Latest Latest
Warning

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

Go to latest
Published: Apr 21, 2024 License: Apache-2.0 Imports: 7 Imported by: 22

README

GoKit - xip

IP kits for Golang development.

Installation

go get -u github.com/likexian/gokit

Importing

import (
    "github.com/likexian/gokit/xip"
)

Documentation

Visit the docs on GoDoc

Example

Check string is a valid ip
ok := xip.IsIP("1.1.1.1")
fmt.Println("1.1.1.1 is a ip:", ok)
IPv4 ip2long
i, err := IPv4ToLong("1.1.1.1")
if err == nil {
    fmt.Println("1.1.1.1 ip2long is:", i)
}
IPv4 long2ip
ip := LongToIPv4(16843009)
fmt.Println("16843009 long2ip is:", ip)

License

Copyright 2012-2024 Li Kexian

Licensed under the Apache License 2.0

Donation

If this project is helpful, please share it with friends.

If you want to thank me, you can give me a cup of coffee.

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrInvalidIP ip value is invalid
	ErrInvalidIP = errors.New("xip: not valid ip string")
	// ErrInvalidMask ip mask value is invalid
	ErrInvalidMask = errors.New("xip: not valid ip mask")
	// ErrInvalidHex hex string is invalid
	ErrInvalidHex = errors.New("xip: not valid hex string")
)
View Source
var PrivateIPs = []string{
	"10.0.0.0/8",
	"172.16.0.0/12",
	"192.168.0.0/16",
	"100.64.0.0/10",
	"fc00::/7",
}

PrivateIPs is private ip

Functions

func Author

func Author() string

Author returns package author

func FixSubnet

func FixSubnet(ip string) (string, error)

FixSubnet fix ip with a subnet mask, for example: 1.2.3.4/24, 2001:700:300::/48

func GetEthIPv4

func GetEthIPv4() (ips []string, err error)

GetEthIPv4 returns all interface ipv4 without loopback

func GetEthIPv4ByInterface

func GetEthIPv4ByInterface(name string) (ips []string, err error)

GetEthIPv4ByInterface returns interface ipv4 by name

func GetEthIPv6

func GetEthIPv6() (ips []string, err error)

GetEthIPv6 returns all interface ipv6 without loopback

func GetEthIPv6ByInterface

func GetEthIPv6ByInterface(name string) (ips []string, err error)

GetEthIPv6ByInterface returns interface ipv6 by name

func HexToUint32

func HexToUint32(s string) (uint32, error)

HexToUint32 returns uint32 from hex string

func IPv4ToLong

func IPv4ToLong(ip string) (uint32, error)

IPv4ToLong returns uint32 of ip, -1 for error

func IsContains

func IsContains(cidr, ip string) bool

IsContains returns if ip is in cidr

func IsIP

func IsIP(ip string) bool

IsIP returns if string is a ip

func IsIPv4

func IsIPv4(ip string) bool

IsIPv4 returns if string is a ipv4

func IsIPv6

func IsIPv6(ip string) bool

IsIPv6 returns if string is a ipv6

func IsPrivate

func IsPrivate(ip string) bool

IsPrivate return ip is private

func License

func License() string

License returns package license

func LongToIPv4

func LongToIPv4(ip uint32) string

LongToIPv4 returns string from uint32 of ip

func Uint32ToHex

func Uint32ToHex(i uint32) string

Uint32ToHex returns hex from uint32

func Version

func Version() string

Version returns package version

Types

This section is empty.

Jump to

Keyboard shortcuts

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