Skip to content

Commit

Permalink
Merge pull request #19 from ipinfo/uman/grepip
Browse files Browse the repository at this point in the history
grepip
  • Loading branch information
UmanShahzad authored Mar 31, 2021
2 parents 443d082 + f564ff7 commit 43ea452
Show file tree
Hide file tree
Showing 27 changed files with 982 additions and 402 deletions.
12 changes: 6 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -47,12 +47,12 @@ After choosing a platform `PLAT` from above, run:

```bash
# for Windows, use ".zip" instead of ".tar.gz"
$ curl -L https://github.com/ipinfo/cli/releases/download/1.0.0b2/ipinfo_1.0.0b2_${PLAT}.tar.gz
$ curl -L https://github.com/ipinfo/cli/releases/download/1.0.0b3/ipinfo_1.0.0b3_${PLAT}.tar.gz
# OR
$ wget https://github.com/ipinfo/cli/releases/download/1.0.0b2/ipinfo_1.0.0b2_${PLAT}.tar.gz
$ wget https://github.com/ipinfo/cli/releases/download/1.0.0b3/ipinfo_1.0.0b3_${PLAT}.tar.gz

$ tar -xvf ipinfo_1.0.0b2_${PLAT}.tar.gz
$ mv ipinfo_1.0.0b2_${PLAT} /usr/local/bin/ipinfo
$ tar -xvf ipinfo_1.0.0b3_${PLAT}.tar.gz
$ mv ipinfo_1.0.0b3_${PLAT} /usr/local/bin/ipinfo
```

### Using Homebrew
Expand All @@ -64,8 +64,8 @@ $ mv ipinfo_1.0.0b2_${PLAT} /usr/local/bin/ipinfo
The `ipinfo` binary will be installed in `/usr/local/bin/ipinfo`:

```bash
$ curl -L https://github.com/ipinfo/cli/releases/download/1.0.0b2/ipinfo_1.0.0b2.deb
$ sudo dpkg -i ipinfo_1.0.0b2.deb
$ curl -L https://github.com/ipinfo/cli/releases/download/1.0.0b3/ipinfo_1.0.0b3.deb
$ sudo dpkg -i ipinfo_1.0.0b3.deb
```

### Using Linux package managers
Expand Down
25 changes: 13 additions & 12 deletions ipinfo/cmd_bulk.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"net"
"os"

"github.com/ipinfo/cli/lib"
"github.com/ipinfo/go/v2/ipinfo"
"github.com/spf13/pflag"
)
Expand Down Expand Up @@ -85,21 +86,21 @@ func cmdBulk() (err error) {
fmt.Println("** manual input mode **")
fmt.Println("Enter all IPs, one per line:")
}
ips = ipsFromStdin()
ips = lib.IPsFromStdin()

goto lookup
}

// check for IP range.
if isIP(args[0]) {
if lib.IsIP(args[0]) {
if len(args) != 2 {
return errIPRangeRequiresTwoIPs
return lib.ErrIPRangeRequiresTwoIPs
}
if !isIP(args[1]) {
return errNotIP
if !lib.IsIP(args[1]) {
return lib.ErrNotIP
}

ips, err = ipsFromRange(args[0], args[1])
ips, err = lib.IPsFromRange(args[0], args[1])
if err != nil {
return err
}
Expand All @@ -108,14 +109,14 @@ func cmdBulk() (err error) {
}

// check for all CIDRs.
if isCIDR(args[0]) {
if lib.IsCIDR(args[0]) {
for _, arg := range args[1:] {
if !isCIDR(arg) {
return errNotCIDR
if !lib.IsCIDR(arg) {
return lib.ErrNotCIDR
}
}

ips, err = ipsFromCIDRs(args)
ips, err = lib.IPsFromCIDRs(args)
if err != nil {
return err
}
Expand All @@ -127,11 +128,11 @@ func cmdBulk() (err error) {
if fileExists(args[0]) {
for _, arg := range args[1:] {
if !fileExists(arg) {
return errNotFile
return lib.ErrNotFile
}
}

ips, err = ipsFromFiles(args)
ips, err = lib.IPsFromFiles(args)
if err != nil {
return err
}
Expand Down
4 changes: 3 additions & 1 deletion ipinfo/cmd_default.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"net"
"os"

"github.com/ipinfo/cli/lib"
"github.com/ipinfo/go/v2/ipinfo"
"github.com/spf13/pflag"
)
Expand All @@ -20,6 +21,7 @@ Commands:
bulk get details for multiple IPs in bulk.
summarize get summarized data for a group of IPs.
prips print IP list from CIDR or range.
grepip grep for IPs matching criteria from any source.
login save an API token session.
logout delete your current API token session.
version show current version.
Expand Down Expand Up @@ -86,7 +88,7 @@ func cmdDefault() (err error) {
return err
}

ips = ipsFromStdin()
ips = lib.IPsFromStdin()

if len(ips) == 0 {
fmt.Println("no input ips")
Expand Down
Loading

0 comments on commit 43ea452

Please sign in to comment.