Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/xgfone/go-netaddr
This is a Go implemenation of `IPAddress` and `IPNetwork` in the Python package [`netaddr`](https://pypi.org/project/netaddr/). See [godoc](https://godoc.org/github.com/xgfone/netaddr).
https://github.com/xgfone/go-netaddr
address ipv4 ipv4-address ipv4-network ipv6 ipv6-address ipv6-network netaddr network
Last synced: about 1 month ago
JSON representation
This is a Go implemenation of `IPAddress` and `IPNetwork` in the Python package [`netaddr`](https://pypi.org/project/netaddr/). See [godoc](https://godoc.org/github.com/xgfone/netaddr).
- Host: GitHub
- URL: https://github.com/xgfone/go-netaddr
- Owner: xgfone
- License: apache-2.0
- Created: 2018-06-03T05:35:26.000Z (over 6 years ago)
- Default Branch: master
- Last Pushed: 2023-04-01T12:49:27.000Z (almost 2 years ago)
- Last Synced: 2024-12-03T16:47:40.722Z (about 1 month ago)
- Topics: address, ipv4, ipv4-address, ipv4-network, ipv6, ipv6-address, ipv6-network, netaddr, network
- Language: Go
- Size: 31.3 KB
- Stars: 10
- Watchers: 5
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# netaddr [![Build Status](https://github.com/xgfone/go-netaddr/actions/workflows/go.yml/badge.svg)](https://github.com/xgfone/go-netaddr/actions/workflows/go.yml) [![GoDoc](https://pkg.go.dev/badge/github.com/xgfone/go-netaddr)](https://pkg.go.dev/github.com/xgfone/go-netaddr) [![License](https://img.shields.io/badge/License-Apache%202.0-blue.svg?style=flat-square)](https://raw.githubusercontent.com/xgfone/go-netaddr/master/LICENSE)
This is a Go implemenation supporting `Go1.7+` of `IPAddress` and `IPNetwork` in the Python package [`netaddr`](https://pypi.org/project/netaddr/). See [godoc](https://pkg.go.dev/github.com/xgfone/go-netaddr).
## Usage
#### IP Address
```go
// IPv6
ip := MustNewIPAddress("fe80::d656:43a8:fc42:948c")
fmt.Println(ip) // fe80::d656:43a8:fc42:948cv1 := ip.Value()
fmt.Println(ip.Equal(MustNewIPAddress(v1, ip.Version()))) // true// IPv4
ip = MustNewIPAddress("192.168.10.10")
fmt.Println(ip) // 192.168.10.10v2 := ip.Value()
fmt.Println(ip.Equal(MustNewIPAddress(v2, ip.Version()))) // true
```#### IP Network
```go
net := MustNewIPNetwork("192.168.10.10/24")fmt.Println(net.Network()) // 192.168.10.0
fmt.Println(net.Broadcast()) // 192.168.10.255
fmt.Println(net.NetworkMask()) // 255.255.255.0
fmt.Println(net.HostMask()) // 0.0.0.255
fmt.Println(net.First()) // 192.168.10.0
fmt.Println(net.Last()) // 192.168.10.255
fmt.Println(net.CIDR()) // 192.168.10.0/24
fmt.Println(net.HasStringIP("192.168.10.0")) // true
fmt.Println(net.HasStringIP("192.168.11.0")) // false
fmt.Println(net.Size()) // 16
fmt.Println(net.Previous()) // 192.168.9.0/24
fmt.Println(net.Next()) // 192.168.11.0/24
fmt.Println(net.Contains(MustNewIPNetwork("192.168.10.0/28"))) // true
```