Giter Site home page Giter Site logo

cidr's Introduction

CIDR (Classless inter-domain routing)

This Package converts IP CIDR to range and return First IP, Last IP, First IP decimal, Last IP decimal and Total Host count for IPv4 and IPv6

Install

go get -u github.com/m7shapan/cidr

How to use

See the GoDoc

package main

import (
	"fmt"
	"log"

	"github.com/m7shapan/cidr"
)

func main() {
	p, err := cidr.ParseCIDR("1.0.0.0/24")
	if err != nil {
		log.Fatal(err)
	}

	fmt.Println("First IP:", p.FirstIP)
	if p.IsIPv4 {
		fmt.Println("First IP (Decimal):", p.FirstIPv4())
	} else {
		fmt.Println("First IP (Decimal):", p.FirstIPv6())
	}

	fmt.Println("Last IP:", p.LastIP)

	if p.IsIPv4 {
		fmt.Println("Last IP (Decimal):", p.LastIPv4())
	} else {
		fmt.Println("Last IP (Decimal):", p.LastIPv6())
	}

	if p.IsIPv4 {
		fmt.Println("Total Host:", p.HostCountIPv4())
	} else {
		fmt.Println("Total Host:", p.HostCountIPv6())
	}

	// First IP: 1.0.0.0
	// First IP (Decimal): 16777216
	// Last IP: 1.0.0.255
	// Last IP (Decimal): 16777471
	// Total Host: 256


	ip := net.ParseIP("1.0.0.0")
	fmt.Println(IPv4tod(ip)) // 16777216

	ip := net.ParseIP("2001:4860:4860::8888")
	fmt.Println(IPv6tod(ip)) // 42541956123769884636017138956568135816

	var i uint32 = 16777216
	fmt.Println(DtoIPv4(i)) // 1.0.0.0

	b := new(big.Int)
	b.SetString("42541956123769884636017138956568135816", 10)
	fmt.Println(DtoIPv6(b)) // 2001:4860:4860::8888

}

Package usage for SEO

  • get ip from ip range
  • convert ip range to ip
  • golang convert ip range to decimal
  • How to get first/last IP address of CIDR
  • Convert IP version 6 address to integer or decimal number
  • IPv4 to IP Decimal Conversion
  • ipv4 to decimal golang

cidr's People

Contributors

m7shapan avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.