ipcheck

package module
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Jan 21, 2024 License: MIT Imports: 2 Imported by: 0

README

IPCheck

Go Reference

Overview

IPCheck is a Go package that provides utilities for IP address classification. It includes functions to determine if an IP address should not be routed.

Installation

To use IPCheck in your Go project, install it using go get:

go get github.com/point-c/ipcheck

Usage

Checking IP Address Types

To check the type of an IP address, you can use the following functions:

  • IsLinkLocal(ip net.IP) bool: Determines if the IP is a link-local address.
  • IsLoopback(ip net.IP) bool: Checks if the IP is a loopback address.
  • IsPrivateNetwork(ip net.IP) bool: Identifies if the IP belongs to a private network.
  • IsBogon(ip net.IP, extra ...func(net.IP) bool) bool: Determines if the IP is a not a routable address.
Example

Here's a simple example demonstrating the usage of the IPCheck package:

package main

import (
    "fmt"
    "net"
    "github.com/point-c/ipcheck"
)

func main() {
    ip := net.ParseIP("192.168.1.1")

    if ipcheck.IsPrivateNetwork(ip) {
        fmt.Println("The IP address is part of a private network")
    }
}

Testing

The package includes tests that demonstrate its functionality. Use Go's testing tools to run the tests:

go test

Godocs

To regenerate godocs:

go generate -tags docs ./...

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrInvalidLocalIP  = errors.New("local ip is invalid")
	ErrInvalidRemoteIP = errors.New("remote ip is invalid")
)

Error variables for invalid IP addresses

Functions

func IsBogon

func IsBogon(ip net.IP, extra ...func(net.IP) bool) bool

IsBogon returns true if dialing the address would fail due to gonet restrictions. A bogon address is a packet routed on the public internet that claims to originate from an area of the IP address space reserved or not yet allocated. This function checks against known bogon conditions including loopback, link-local, and other special addresses. Additional conditions can be specified through the extra parameter.

func IsLinkLocal

func IsLinkLocal(ip net.IP) bool

IsLinkLocal determines if the provided IP address is a link-local address. Link-local addresses are used in a single network segment and not routable on the larger internet. This function checks if the IP belongs to the IPv4 link-local range (169.254.0.0/16) or the IPv6 link-local range (fe80::/64).

func IsLoopback

func IsLoopback(ip net.IP) bool

IsLoopback determines if the IP is either the standard IPv6 loopback (::1) or within the IPv4 loopback range.

func IsPrivateNetwork

func IsPrivateNetwork(ip net.IP) bool

IsPrivateNetwork returns true if the address belongs to a private network. This function checks against standard private IPv4 ranges (10.0.0.0/8, 172.16.0.0/12, 192.168.0.0/16) and the IPv6 unique local address range (fd00::/8).

Types

This section is empty.

Jump to

Keyboard shortcuts

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