/subneter

A library to query and manipulate subnets for ipv4 and ipv6

Primary LanguageGoMIT LicenseMIT

Build Status Go doc MIT License Go Report Card

Subneter

Library for IPv4 Subnetting

What does it do?

Given a cidr address, it calculates

  • Network Id
  • First usable IP
  • Last usable IP
  • Broadcast address
package main

import (
	"fmt"
	"github.com/milindacharya/subneter"
)

func main() {
	s, _ := subneter.CidrToSubneter("192.168.1.15/25")
	fmt.Printf("Network Address: %s\n", s.NetworkID)
	fmt.Printf("First Host: %s\n", s.FirstHost)
	fmt.Printf("Last Host: %s\n", s.LastHost)
	fmt.Printf("Broadcast Address: %s\n", s.BroadcastIP)
}

Output is

Network Address: 192.168.1.0
First Host: 192.168.1.1
Last Host: 192.168.1.126
Broadcast Address: 192.168.1.127

More to come... (work in progress)

  • Given a subnet

    • return all possible subnets with same network mask
    • divide it further into subnets to have x number of hosts per subnet
    • divide it into y number of networks
    • optimally divide it into x number of networks with y number of hosts if possible
  • IPv6 support