Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/tty47/go-cidr
Network CIDR checker, it will check from a network CIDR if contains an IP which you send.
https://github.com/tty47/go-cidr
cidr go golang ip ip-add ip-ranges network
Last synced: 6 days ago
JSON representation
Network CIDR checker, it will check from a network CIDR if contains an IP which you send.
- Host: GitHub
- URL: https://github.com/tty47/go-cidr
- Owner: tty47
- License: other
- Created: 2021-09-06T16:21:46.000Z (over 3 years ago)
- Default Branch: master
- Last Pushed: 2022-04-06T15:13:13.000Z (almost 3 years ago)
- Last Synced: 2024-12-22T03:32:30.368Z (2 months ago)
- Topics: cidr, go, golang, ip, ip-add, ip-ranges, network
- Language: Go
- Homepage: https://pkg.go.dev/github.com/jrmanes/go-cidr
- Size: 16.6 KB
- Stars: 1
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Go-CIDR
[](https://pkg.go.dev/github.com/jrmanes/go-cidr)
[](https://goreportcard.com/report/github.com/jrmanes/go-cidr)---
## Description
The purpose of that library is checked an IP inside from a CIDR.
---
## Project structure
The project structure explained what contains what.
```shell
├── cmd
│ ├── bootstrap
│ │ └── bootstrap.go // point where init the service
│ └── main.go // entrypoint of the service
├── pkg
│ ├── config
│ │ └── config.go // config structs, methods and functions
│ ├── ip
│ │ ├── ip.go // logic to create the hosts from cirds
│ │ └── ip_test.go // test file for ip pkg
│ └── store
│ └── memory
│ └── memory.go // storage in memory
└── README.md // Readme
```----
## Example
Using storage in memory:
```go
package mainimport (
"time"
"log"b "github.com/jrmanes/go-cidr/cmd/bootstrap"
m "github.com/jrmanes/go-cidr/pkg/store/memory"
)func main() {
// load configuration
cidr := []string{"10.251.0.0/16", "172.18.0.0/16", "192.168.0.0/16"}// Run the process in order to load the hosts inside the cidr
b.Run(cidr)now := time.Now()
log.Println("---------FROM MEMORY------------")
ip2CheckInMemory := "12.251.0.162"
existsInMemory := m.CheckIfIpExistsInMemory(ip2CheckInMemory)
if existsInMemory {
log.Println("IP found ip2CheckInMemory (", ip2CheckInMemory, ")", existsInMemory)
} else {
log.Println("IP NOT found ip2CheckInMemory (", ip2CheckInMemory, ")", existsInMemory)
}
log.Println("elapse using storage memory:", time.Since(now))
log.Println("-----------------------------")
}
```----
## TODO
- [ ] Change project structure
- [ ] Release 2.0.0
- [ ] Add more test----
Jose Ramón Mañes
---