Skip to content

Commit

Permalink
v1.1.0
Browse files Browse the repository at this point in the history
- 变更了主函数接口
- 新增根据序号从IP集获得IP的功能
  • Loading branch information
XinRoom committed Nov 5, 2021
1 parent 12f9cac commit 9b08761
Show file tree
Hide file tree
Showing 4 changed files with 292 additions and 169 deletions.
110 changes: 65 additions & 45 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,77 @@

This is a tool for generating IP SETS from a given IP range string.

## Build
## Use as a library

import: `import "github.com/XinRoom/iprange"`

Simple to use:

```go
package main

import "github.com/XinRoom/iprange"
import "fmt"

func main() {
ipSet, err := iprange.GenIpSet("1.1.1.1/30")
if err != nil {
fmt.Println(err)
return
}
fmt.Sprintln("1.1.1.1/30 GenIpSet is %s", ipSet)
}
```

Iterator (Save memory) 迭代器(省内存):

```go
package main

import "github.com/XinRoom/iprange"
import "fmt"

func main() {
it, startIp, err := iprange.NewIter("1.1.1.1/30")
if err != nil {
fmt.Println(err)
return
}
for itn := startIp; it.HasNext(); itn = it.Next() {
fmt.Println(itn)
}
}
```

GetIpByIndex (For random IP and progress) 通过索引获取IP(可用于乱序IP生成和进度恢复):

```go
package main

import "github.com/XinRoom/iprange"
import "fmt"

func main() {
it, _, err := iprange.NewIter("1.1.1.1/30")
if err != nil {
fmt.Println(err)
return
}
for i := uint64(0); i < it.TotalNum(); i++ {
fmt.Println(it.GetIpByIndex(i))
}
}
```

## Cmd Build

```
git clone https://github.com/XinRoom/iprange
cd iprange
go build cmd/iprange.go
```

## Usage
## Cmd Usage

```
.\iprange.exe
Expand All @@ -31,7 +93,7 @@ IP format can :
in addition: Support multiple parameters, file and commas
```

## Feature
## Cmd Feature

### 1. CidrMode 1.1.1.1/30

Expand Down Expand Up @@ -95,45 +157,3 @@ echo 1.1.1.2-5 | .\iprange.exe
1.1.1.4
1.1.1.5
```

## Use as a library

import: `import "github.com/Xinroom/iprange"`

Simple to use:

```go
package main

import "github.com/XinRoom/iprange"
import "fmt"

func main() {
ipSet, err := iprange.GenIpSet("1.1.1.1/30")
if err != nil {
fmt.Println(err)
return
}
fmt.Sprintln("1.1.1.1/30 GenIpSet is %s", ipSet)
}
```

Iterator (Save memory):

```go
package main

import "github.com/XinRoom/iprange"
import "fmt"

func main() {
it, err := iprange.NewIter("1.1.1.1/30")
if err != nil {
fmt.Println(err)
return
}
for itn := it.Next(); it.HasNext(); itn = it.Next() {
fmt.Println(itn)
}
}
```
4 changes: 2 additions & 2 deletions cmd/iprange.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,12 +61,12 @@ func main() {
if v == "" {
continue
}
it, err := iprange.NewIter(v)
it, startIp, err := iprange.NewIter(v)
if err != nil {
fmt.Fprintf(os.Stderr, "[error] %s is not ip!\n", v)
continue
}
for nit := it.Next(); it.HasNext(); nit = it.Next() {
for nit := startIp; it.HasNext(); nit = it.Next() {
fmt.Println(nit)
}
}
Expand Down
Loading

0 comments on commit 9b08761

Please sign in to comment.