bogon

package module
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Mar 3, 2023 License: MIT Imports: 4 Imported by: 1

README

go-bogon -- Go package to check if an IP address is a bogon (internal) IP address

🔗 Table of Contents

What

go-bogon is a basic package to check if an IP is within the bogon IP ranges or not.

  • No-frills check for the common default bogon IP ranges: bogon.Is("127.0.0.1")
  • You can supply your own CIDR's if you wish: bogon.New([]string{"0.0.0.0/8"})

Usage

$ go get -u github.com/lrstanley/go-bogon@latest

🙋♂ Support & Assistance

  • ❤ Please review the Code of Conduct for guidelines on ensuring everyone has the best experience interacting with the community.
  • 🙋♂ Take a look at the support document on guidelines for tips on how to ask the right questions.
  • 🐞 For all features/bugs/issues/questions/etc, head over here.

🤝 Contributing

  • ❤ Please review the Code of Conduct for guidelines on ensuring everyone has the best experience interacting with the community.
  • 📋 Please review the contributing doc for submitting issues/a guide on submitting pull requests and helping out.
  • 🗝 For anything security related, please review this repositories security policy.

⚖ License

MIT License

Copyright (c) 2017 Liam Stanley <me@liamstanley.io>

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.

Also located here

Documentation

Overview

Package bogon provides a simply interface to check if an IP address is a "bogon" IP (an internal IP that should not be hitting external services), or a custom specified range of CIDR's.

Note that you can use bogon.New() to check your own ranges.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func DefaultRanges

func DefaultRanges() []*net.IPNet

DefaultRanges returns the default list of bogon IP CIDRs.

func Is

func Is(ip string) (isIn bool, representation string)

Is checks if the IP address is within the default Bogon IP ranges. Representation is non-nil if the match is a success, and it contains the string representation of the CIDR notation that it matched.

Check the main docs for which IP's are checked within this.

func MustCIDR

func MustCIDR(cidr string) *net.IPNet

MustCIDR converts a string representation of a CIDR notation, to a net.IPNet. If it is an invalid CIDR, MustCIDR will throw a panic.

Types

type Bogon

type Bogon struct {
	// contains filtered or unexported fields
}

Bogon is a helper utility to use your own IP ranges.

func New

func New(cidrList []string) (*Bogon, error)

New returns a new Bogon instance. Use this if you have your own CIDR ranges that you would like to check. An error is returned if a nil list is supplied or if one of the supplied CIDR's is invalid.

func (*Bogon) Is

func (b *Bogon) Is(ip string) (isIn bool, representation string)

Is checks if the IP address is within the custom Bogon IP ranges specified during the creation of the Bogon instance. representation is non-nil if the match is a success, and it contains the string representation of the CIDR notation that it matched.

func (*Bogon) Ranges

func (b *Bogon) Ranges() []*net.IPNet

Ranges returns the underlying IP CIDR ranges used for checks within Bogon.

func (*Bogon) String

func (b *Bogon) String() string

String returns a string representation of each CIDR within Bogon.

Jump to

Keyboard shortcuts

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