Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
7 changes: 5 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,12 @@ require (
github.com/spf13/pflag v1.0.5
github.com/stretchr/testify v1.8.0
go.etcd.io/bbolt v1.3.6
golang.org/x/term v0.0.0-20201210144234-2321bbc49cbf
golang.org/x/term v0.14.0
gopkg.in/yaml.v3 v3.0.1
)

require golang.org/x/text v0.14.0 // indirect

require (
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/hashicorp/errwrap v1.1.0 // indirect
Expand All @@ -28,7 +30,8 @@ require (
github.com/pmezard/go-difflib v1.0.0 // indirect
go4.org/intern v0.0.0-20220617035311-6925f38cc365 // indirect
go4.org/unsafe/assume-no-moving-gc v0.0.0-20230525183740-e7c30c78aeb2 // indirect
golang.org/x/net v0.18.0
golang.org/x/sync v0.0.0-20220513210516-0976fa681c29 // indirect
golang.org/x/sys v0.0.0-20220811171246-fbc7d0a398ab // indirect
golang.org/x/sys v0.14.0 // indirect
inet.af/netaddr v0.0.0-20220811202034-502d2d690317 // indirect
)
8 changes: 8 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,8 @@ golang.org/x/mod v0.3.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA=
golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg=
golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
golang.org/x/net v0.0.0-20201021035429-f5854403a974/go.mod h1:sp8m0HH+o8qH0wwXwYZr8TS3Oi6o0r6Gce1SSxlDquU=
golang.org/x/net v0.18.0 h1:mIYleuAkSbHh0tCv7RvjL3F6ZVbLjq4+R7zbOn3Kokg=
golang.org/x/net v0.18.0/go.mod h1:/czyP5RqHAH4odGYxBJ1qz0+CE5WZ+2j1YgoEo8F2jQ=
golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sync v0.0.0-20201020160332-67f06af15bc9/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sync v0.0.0-20220513210516-0976fa681c29 h1:w8s32wxx3sY+OjLlv9qltkLU5yvJzxjjgiHWLjdIcw4=
Expand All @@ -78,10 +80,16 @@ golang.org/x/sys v0.0.0-20210119212857-b64e53b001e4/go.mod h1:h1NjWce9XRLGQEsW7w
golang.org/x/sys v0.0.0-20210630005230-0f9fa26af87c/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20220811171246-fbc7d0a398ab h1:2QkjZIsXupsJbJIdSjjUOgWK3aEtzyuh2mPt3l/CkeU=
golang.org/x/sys v0.0.0-20220811171246-fbc7d0a398ab/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.14.0 h1:Vz7Qs629MkJkGyHxUlRHizWJRG2j8fbQKjELVSNhy7Q=
golang.org/x/sys v0.14.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
golang.org/x/term v0.0.0-20201210144234-2321bbc49cbf h1:MZ2shdL+ZM/XzY3ZGOnh4Nlpnxz5GSOhOmtHo3iPU6M=
golang.org/x/term v0.0.0-20201210144234-2321bbc49cbf/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo=
golang.org/x/term v0.14.0 h1:LGK9IlZ8T9jvdy6cTdfKUCltatMFOehAQo9SRC46UQ8=
golang.org/x/term v0.14.0/go.mod h1:TySc+nGkYR6qt8km8wUhuFRTVSMIX3XPR58y2lC8vww=
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
golang.org/x/text v0.14.0 h1:ScX5w1eTa3QqT8oi6+ziP7dTV1S2+ALU0bI+0zXKWiQ=
golang.org/x/text v0.14.0/go.mod h1:18ZOQIKpY8NJVqYksKHtTdi31H5itFRjB5/qKTNYzSU=
golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
golang.org/x/tools v0.0.0-20191119224855-298f0cb1881e/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo=
golang.org/x/tools v0.1.0/go.mod h1:xkSsbof2nBLbhDlRMhhhyNLN/zl3eTqcnHD5viDpcZ0=
Expand Down
6 changes: 6 additions & 0 deletions grepdom/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# syntax=docker/dockerfile:1
FROM alpine:latest

WORKDIR /grepdom
COPY build/grepdom ./
ENTRYPOINT ["/grepdom/grepdom"]
12 changes: 12 additions & 0 deletions grepdom/build-all-platforms.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#!/bin/bash

# Build binary for all platforms for version $1.

set -e

DIR=`dirname $0`
ROOT=$DIR/..

VSN=$1

$ROOT/scripts/build-all-platforms.sh "grepdom" $VSN
10 changes: 10 additions & 0 deletions grepdom/build.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
#!/bin/bash

# Build local binary.

set -e

DIR=`dirname $0`
ROOT=$DIR/..

$ROOT/scripts/build.sh "grepdom"
29 changes: 29 additions & 0 deletions grepdom/completions.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
package main

import (
"github.com/ipinfo/cli/lib/complete"
"github.com/ipinfo/cli/lib/complete/predict"
)

var completions = &complete.Command{
Flags: map[string]complete.Predictor{
"-o": predict.Nothing,
"--only-matching": predict.Nothing,
"-h": predict.Nothing,
"--no-filename": predict.Nothing,
"--no-recurse": predict.Nothing,
"--version": predict.Nothing,
"--help": predict.Nothing,
"--nocolor": predict.Nothing,
"--no-punycode": predict.Nothing,
"-n": predict.Nothing,
"--completions-install": predict.Nothing,
"--completions-bash": predict.Nothing,
"--completions-zsh": predict.Nothing,
"--completions-fish": predict.Nothing,
},
}

func handleCompletions() {
completions.Complete(progBase)
}
14 changes: 14 additions & 0 deletions grepdom/deb.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
#!/bin/sh

VSN=1.0.0

curl -LO https://github.com/ipinfo/cli/releases/download/grepdom-${VSN}/grepdom_${VSN}.deb
sudo dpkg -i grepdom_${VSN}.deb
rm grepdom_${VSN}.deb

echo
echo 'You can now run `grepdom`'.

if [ -f "$0" ]; then
rm $0
fi
11 changes: 11 additions & 0 deletions grepdom/dist/DEBIAN/control
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
Source: grepdom
Section: utils
Version: 1.0.0
Priority: optional
Maintainer: IPinfo <support@ipinfo.io>
Vcs-Git: https://github.com/ipinfo/cli
Vcs-browser: https://github.com/ipinfo/cli
Homepage: https://ipinfo.io
Package: grepdom
Architecture: amd64
Description: A grep-like tool for matching domain names.
14 changes: 14 additions & 0 deletions grepdom/docker.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
#!/bin/bash

# Build and upload (to Dockerhub) for all platforms for version $1.
# Use `-r` or `--release` after the version to also push to Dockerhub.

set -e

DIR=`dirname $0`
ROOT=$DIR/..

VSN=$1
RELEASE=$2

$ROOT/scripts/docker.sh "grepdom" $VSN $RELEASE
16 changes: 16 additions & 0 deletions grepdom/macos.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
#!/bin/sh

VSN=1.0.0
PLAT=darwin_amd64

curl -LO https://github.com/ipinfo/cli/releases/download/grepdom-${VSN}/grepdom_${VSN}_${PLAT}.tar.gz
tar -xf grepdom_${VSN}_${PLAT}.tar.gz
rm grepdom_${VSN}_${PLAT}.tar.gz
mv grepdom_${VSN}_${PLAT} /usr/local/bin/grepdom

echo
echo 'You can now run `grepdom`'.

if [ -f "$0" ]; then
rm $0
fi
136 changes: 136 additions & 0 deletions grepdom/main.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,136 @@
package main

import (
"fmt"
"os"
"path/filepath"

"github.com/fatih/color"
"github.com/ipinfo/cli/lib"
"github.com/ipinfo/cli/lib/complete/install"
"github.com/spf13/pflag"
)

var progBase = filepath.Base(os.Args[0])
var version = "1.0.0"

func printHelp() {
fmt.Printf(
`Usage: %s [<opts>]

Options:
General:
--only-matching, -o
print only matched domains in result line, excluding surrounding content.
--no-filename, -h
don't print source of match in result lines when more than 1 source.
--no-recurse
don't recurse into more directories in directory sources.
--version
show binary release number.
--help
show help.

Outputs:
--nocolor
disable colored output.

Filters:
--no-punycode, -n
do not convert domains to punycode.

Completions:
--completions-install
attempt completions auto-installation for any supported shell.
--completions-bash
output auto-completion script for bash for manual installation.
--completions-zsh
output auto-completion script for zsh for manual installation.
--completions-fish
output auto-completion script for fish for manual installation.
`, progBase)
}

func cmd() error {
var fVsn bool
var fCompletionsInstall bool
var fCompletionsBash bool
var fCompletionsZsh bool
var fCompletionsFish bool

f := lib.CmdGrepDomainFlags{}
f.Init()
pflag.BoolVarP(
&fVsn,
"version", "", false,
"print binary release number.",
)
pflag.BoolVarP(
&fCompletionsInstall,
"completions-install", "", false,
"attempt completions auto-installation for any supported shell.",
)
pflag.BoolVarP(
&fCompletionsBash,
"completions-bash", "", false,
"output auto-completion script for bash for manual installation.",
)
pflag.BoolVarP(
&fCompletionsZsh,
"completions-zsh", "", false,
"output auto-completion script for zsh for manual installation.",
)
pflag.BoolVarP(
&fCompletionsFish,
"completions-fish", "", false,
"output auto-completion script for fish for manual installation.",
)
pflag.Parse()

if fVsn {
fmt.Println(version)
return nil
}

if fCompletionsInstall {
return install.Install(progBase)
}
if fCompletionsBash {
installStr, err := install.BashCmd(progBase)
if err != nil {
return err
}
fmt.Println(installStr)
return nil
}
if fCompletionsZsh {
installStr, err := install.ZshCmd(progBase)
if err != nil {
return err
}
fmt.Println(installStr)
return nil
}
if fCompletionsFish {
installStr, err := install.FishCmd(progBase)
if err != nil {
return err
}
fmt.Println(installStr)
return nil
}

return lib.CmdGrepDomain(f, pflag.Args(), printHelp)
}

func main() {
if os.Getenv("NO_COLOR") != "" {
color.NoColor = true
}

handleCompletions()

if err := cmd(); err != nil {
fmt.Printf("err: %v\n", err)
}
}
12 changes: 12 additions & 0 deletions grepdom/release.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#!/bin/bash

# Build and upload (to GitHub) for all platforms for version $1.

set -e

DIR=`dirname $0`
ROOT=$DIR/..

VSN=$1

$ROOT/scripts/release.sh "grepdom" $VSN
34 changes: 34 additions & 0 deletions grepdom/windows.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
$VSN = "1.0.0"

# build the filename for the Zip archive and exe file
$FileName = "grepdom_$($VSN)_windows_amd64"
$ZipFileName = "$($FileName).zip"

# download and extract zip
Invoke-WebRequest -Uri "https://github.com/ipinfo/cli/releases/download/grepdom-$VSN/$FileName.zip" -OutFile ./$ZipFileName
Unblock-File ./$ZipFileName
Expand-Archive -Path ./$ZipFileName -DestinationPath $env:LOCALAPPDATA\ipinfo -Force

# delete if already exists
if (Test-Path "$env:LOCALAPPDATA\ipinfo\grepdom.exe") {
Remove-Item "$env:LOCALAPPDATA\ipinfo\grepdom.exe"
}
Rename-Item -Path "$env:LOCALAPPDATA\ipinfo\$FileName.exe" -NewName "grepdom.exe"

# setting up env.
$PathContent = [Environment]::GetEnvironmentVariable('path', 'Machine')
$IPinfoPath = "$env:LOCALAPPDATA\ipinfo"

# if Path already exists
if ($PathContent -ne $null) {
if (-Not($PathContent -split ';' -contains $IPinfoPath)) {
[System.Environment]::SetEnvironmentVariable("PATH", $Env:Path + ";$env:LOCALAPPDATA\ipinfo", "Machine")
}
}
else {
[System.Environment]::SetEnvironmentVariable("PATH", $Env:Path + ";$env:LOCALAPPDATA\ipinfo", "Machine")
}

# cleaning files
Remove-Item -Path ./$ZipFileName
"You can use grepdom now."
1 change: 1 addition & 0 deletions ipinfo/cmd_default.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ Commands:
map open a URL to a map showing the locations of a group of IPs.
prips print IP list from CIDR or range.
grepip grep for IPs matching criteria from any source.
grepdom grep for domains matching criteria from any source.
cidr2range convert CIDRs to IP ranges.
cidr2ip convert CIDRs to individual IPs within those CIDRs.
range2cidr convert IP ranges to CIDRs.
Expand Down
Loading