├── .github └── workflows │ └── release.yml ├── .gitignore ├── .goreleaser.yml ├── LICENSE ├── Makefile ├── README.md ├── cmd ├── list.go ├── list_test.go ├── lookup.go ├── lookup_test.go ├── root.go ├── scan.go ├── scan_test.go ├── shell.go ├── shell_test.go └── version.txt ├── docs ├── networker.md ├── networker_list.md ├── networker_lookup.md ├── networker_lookup_hostname.md ├── networker_lookup_ip.md ├── networker_lookup_isp.md ├── networker_lookup_nameservers.md ├── networker_lookup_network.md ├── networker_request.md ├── networker_scan.md ├── networker_shell.md ├── networker_shell_dial.md └── networker_shell_serve.md ├── go.mod ├── go.sum ├── internal ├── encoder │ ├── encoder.go │ └── encoder_test.go ├── list │ ├── list.go │ └── list_test.go ├── resolve │ ├── lookup.go │ ├── lookup_test.go │ ├── private.go │ └── private_test.go ├── scanner │ ├── scanner.go │ └── scanner_test.go ├── shell │ ├── dialer.go │ ├── dialer_test.go │ ├── server.go │ └── server_test.go ├── spinner │ └── spinner.go ├── test │ ├── hooks.go │ └── root.go └── usage │ └── fatal.go ├── main.go └── scripts ├── build.sh ├── clean.sh ├── doc_gen.go ├── generate_test_coverage_report.sh └── install.sh /.github/workflows/release.yml: -------------------------------------------------------------------------------- 1 | on: 2 | push: 3 | tags: 4 | - "*" 5 | 6 | jobs: 7 | build: 8 | name: GoReleaser build 9 | runs-on: ubuntu-latest 10 | 11 | steps: 12 | - name: Check out code into the Go module directory 13 | uses: actions/checkout@v2 14 | with: 15 | fetch-depth: 0 16 | 17 | - name: Set Up Go 18 | uses: actions/setup-go@v2 19 | with: 20 | go-version: '1.x' 21 | id: go 22 | 23 | - name: run GoReleaser 24 | uses: goreleaser/goreleaser-action@master 25 | with: 26 | version: latest 27 | args: release --clean -p 2 28 | env: 29 | GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} 30 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | bin 2 | coverage.out -------------------------------------------------------------------------------- /.goreleaser.yml: -------------------------------------------------------------------------------- 1 | project_name: networker 2 | builds: 3 | - main: . 4 | env: 5 | - CGO_ENABLED=0 6 | goos: 7 | - darwin 8 | - linux 9 | - windows 10 | - freebsd 11 | goarch: 12 | - amd64 13 | - arm 14 | - arm64 15 | - mips 16 | goarm: 17 | - 7 18 | ignore: 19 | - goos: freebsd 20 | goarch: arm 21 | - goos: freebsd 22 | goarch: arm64 23 | - goos: freebsd 24 | goarch: mips 25 | - goos: windows 26 | goarch: arm 27 | goarm: 7 28 | - goos: windows 29 | goarch: arm64 30 | - goos: linux 31 | goarch: mips 32 | 33 | archives: 34 | - name_template: "{{ .ProjectName }}_{{ .Version }}_{{ .Os }}_{{ .Arch }}{{ .Arm }}" 35 | format: tar.xz 36 | format_overrides: 37 | - goos: windows 38 | format: zip 39 | wrap_in_directory: true 40 | checksum: 41 | name_template: "{{ .ProjectName }}_{{ .Version }}--sha256_checksums.txt" 42 | release: 43 | draft: true 44 | 45 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2021 Faris Huskovic 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /Makefile: -------------------------------------------------------------------------------- 1 | .PHONY:clean 2 | clean: 3 | @./scripts/clean.sh 4 | 5 | .PHONY:install 6 | install: 7 | @./scripts/install.sh 8 | 9 | .PHONY: test 10 | test: 11 | @go clean -testcache && go test -v ./... 12 | 13 | .PHONY:build 14 | build: clean 15 | @./scripts/build.sh 16 | 17 | .PHONY: coverage 18 | coverage: 19 | @./scripts/generate_test_coverage_report.sh $(mode) 20 | 21 | .PHONY: badge 22 | badge: 23 | @gopherbadger -md="README.md" -png=false 24 | 25 | .PHONY:fmt 26 | fmt: 27 | @goimports -w $(shell find . -name "*.go") && echo "go files formatted" 28 | 29 | .PHONY:commit 30 | commit: fmt 31 | @git add . && git commit --amend --no-edit 32 | 33 | .PHONY: docs 34 | docs: 35 | @go run ./scripts/doc_gen.go 36 | 37 | .PHONY: refresh 38 | refresh: 39 | @GOPROXY=proxy.golang.org go list -m github.com/fuskovic/networker/v3@latest -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Networker 2 | 3 | [![Go Report Card](https://goreportcard.com/badge/github.com/fuskovic/networker/v3)](https://goreportcard.com/report/github.com/fuskovic/networker/v3) 4 | ![gopherbadger-tag-do-not-edit](https://img.shields.io/badge/Go%20Coverage-74%25-brightgreen.svg?longCache=true&style=flat) 5 | 6 | # Features 7 | 8 | - List devices on your LAN 9 | - Port scanning 10 | - Remote TTY 11 | - DNS lookup 12 | 13 | # Installation Methods 14 | 15 | Install globally using Go (requires Go 1.22^) 16 | 17 | go install github.com/fuskovic/networker/v3@latest 18 | 19 | Or Download a pre-compiled binary from the [releases](https://github.com/fuskovic/networker/releases) page. 20 | 21 | 22 | # Verify your installation 23 | 24 | networker -v 25 | 26 | # Documentation 27 | 28 | See [Docs](https://github.com/fuskovic/networker/blob/master/docs/networker.md) for command examples. 29 | -------------------------------------------------------------------------------- /cmd/list.go: -------------------------------------------------------------------------------- 1 | package cmd 2 | 3 | import ( 4 | "context" 5 | "os" 6 | "slices" 7 | 8 | "github.com/spf13/cobra" 9 | 10 | "github.com/fuskovic/networker/v3/internal/encoder" 11 | "github.com/fuskovic/networker/v3/internal/list" 12 | "github.com/fuskovic/networker/v3/internal/spinner" 13 | "github.com/fuskovic/networker/v3/internal/usage" 14 | ) 15 | 16 | func init() { 17 | Root.AddCommand(listCmd) 18 | } 19 | 20 | var listCmd = &cobra.Command{ 21 | Use: "list", 22 | Aliases: []string{"ls"}, 23 | Short: "List information on connected network devices.", 24 | Example: ` 25 | # List devices on network: 26 | 27 | networker list 28 | 29 | # List devices on network(short-hand): 30 | 31 | nw ls 32 | 33 | # List devices on network(short-hand) and output as json: 34 | 35 | nw ls -o json 36 | 37 | # List devices on network(short-hand) and output as yaml: 38 | 39 | nw ls -o yaml 40 | `, 41 | Args: cobra.NoArgs, 42 | Run: func(cmd *cobra.Command, args []string) { 43 | ctx, cancel := context.WithCancel(context.Background()) 44 | defer cancel() 45 | 46 | spinner.Start() 47 | 48 | devices, err := list.Devices(ctx) 49 | if err != nil { 50 | usage.Fatalf(cmd, "failed to list devices: %s", err) 51 | } 52 | 53 | spinner.Stop() 54 | 55 | devices = slices.DeleteFunc(devices, 56 | func(d list.Device) bool { 57 | return d.Hostname == "N/A" && d.RemoteIP == nil 58 | }, 59 | ) 60 | 61 | enc := encoder.New[list.Device](os.Stdout, output) 62 | if err := enc.Encode(devices...); err != nil { 63 | usage.Fatalf(cmd, "failed to encode devices: %s", err) 64 | } 65 | }, 66 | } 67 | -------------------------------------------------------------------------------- /cmd/list_test.go: -------------------------------------------------------------------------------- 1 | package cmd 2 | 3 | import ( 4 | "encoding/json" 5 | "os/exec" 6 | 7 | "testing" 8 | 9 | "github.com/fuskovic/networker/v3/internal/list" 10 | "github.com/fuskovic/networker/v3/internal/test" 11 | "github.com/stretchr/testify/require" 12 | "gopkg.in/yaml.v3" 13 | ) 14 | 15 | func TestListCommand(t *testing.T) { 16 | test.WithNetworker(t, "list devices output as json", func(t *testing.T) { 17 | // start the list command 18 | cmd := exec.Command("networker", "ls", "-o", "json") 19 | stdout, err := cmd.StdoutPipe() 20 | require.NoError(t, err) 21 | require.NoError(t, cmd.Start()) 22 | 23 | // assert we can unmarshal the json output as expected 24 | var devices []list.Device 25 | require.NoError(t, json.NewDecoder(stdout).Decode(&devices)) 26 | require.NoError(t, cmd.Wait()) 27 | 28 | // assert that the devices are not empty 29 | require.True(t, len(devices) > 0) 30 | }) 31 | test.WithNetworker(t, "list devices output as yaml", func(t *testing.T) { 32 | // start the list command 33 | cmd := exec.Command("networker", "ls", "-o", "yaml") 34 | stdout, err := cmd.StdoutPipe() 35 | require.NoError(t, err) 36 | require.NoError(t, cmd.Start()) 37 | 38 | // assert we can unmarshal the yaml output as expected 39 | var devices []list.Device 40 | require.NoError(t, yaml.NewDecoder(stdout).Decode(&devices)) 41 | require.NoError(t, cmd.Wait()) 42 | 43 | // assert that the devices are not empty 44 | require.True(t, len(devices) > 0) 45 | }) 46 | } 47 | -------------------------------------------------------------------------------- /cmd/lookup.go: -------------------------------------------------------------------------------- 1 | package cmd 2 | 3 | import ( 4 | "net" 5 | "os" 6 | 7 | "github.com/fuskovic/networker/v3/internal/encoder" 8 | "github.com/fuskovic/networker/v3/internal/resolve" 9 | "github.com/fuskovic/networker/v3/internal/usage" 10 | "github.com/spf13/cobra" 11 | ) 12 | 13 | func init() { 14 | lookupCmd.AddCommand(lookupIspCmd) 15 | lookupCmd.AddCommand(lookupNameserversCmd) 16 | lookupCmd.AddCommand(lookupHostnameCmd) 17 | lookupCmd.AddCommand(lookupIpaddressCmd) 18 | lookupCmd.AddCommand(lookupNetworkCmd) 19 | Root.AddCommand(lookupCmd) 20 | } 21 | 22 | var lookupCmd = &cobra.Command{ 23 | Use: "lookup", 24 | Aliases: []string{"lu"}, 25 | SuggestFor: []string{}, 26 | Example: ` 27 | # Lookup hostname by IP: 28 | 29 | networker lookup hostname 8.8.8.8 30 | 31 | # Lookup hostname by IP(short-hand): 32 | 33 | nw lu hn 8.8.8.8 34 | 35 | # Lookup hostname by IP(short-hand) and output as json: 36 | 37 | nw lu hn 8.8.8.8 -o json 38 | 39 | # Lookup hostname by IP(short-hand) and output as yaml: 40 | 41 | nw lu hn 8.8.8.8 -o yaml 42 | 43 | # Lookup IP by hostname: 44 | 45 | networker lookup ip dns.google. 46 | 47 | # Lookup IP by hostname(short-hand): 48 | 49 | nw lu ip dns.google. 50 | 51 | # Lookup IP by hostname(short-hand) and output as json: 52 | 53 | nw lu ip dns.google. -o json 54 | 55 | # Lookup IP by hostname(short-hand) and output as yaml: 56 | 57 | nw lu ip dns.google. -o yaml 58 | 59 | # Lookup nameservers by hostname: 60 | 61 | networker lookup nameservers dns.google. 62 | 63 | # Lookup nameservers by hostname(short-hand): 64 | 65 | nw lu ns dns.google. 66 | 67 | # Lookup nameservers by hostname(short-hand) and output as json: 68 | 69 | nw lu ns dns.google. -o json 70 | 71 | # Lookup nameservers by hostname(short-hand) and output as yaml: 72 | 73 | nw lu ns dns.google. -o yaml 74 | 75 | # Lookup ISP by ip or hostname: 76 | 77 | networker lookup isp 8.8.8.8 78 | networker lookup isp dns.google. 79 | 80 | # Lookup ISP by ip or hostname(short-hand): 81 | 82 | nw lu isp 8.8.8.8 83 | nw lu isp dns.google. 84 | 85 | # Lookup ISP by ip or hostname(short-hand) and output as json: 86 | 87 | nw lu isp 8.8.8.8 -o json 88 | nw lu isp dns.google. -o json 89 | 90 | # Lookup ISP by ip or hostname(short-hand) and output as yaml: 91 | 92 | nw lu isp 8.8.8.8 -o yaml 93 | nw lu isp dns.google. -o yaml 94 | 95 | # Lookup network by ip or hostname: 96 | 97 | networker lookup network 8.8.8.8 98 | networker lookup network dns.google. 99 | 100 | # Lookup network by ip or hostname(short-hand): 101 | 102 | nw lu n 8.8.8.8 103 | nw lu n dns.google. 104 | 105 | # Lookup network by ip or hostname(short-hand) and output as json: 106 | 107 | nw lu n 8.8.8.8 -o json 108 | nw lu n dns.google. -o json 109 | 110 | # Lookup network by ip or hostname(short-hand) and output as yaml: 111 | 112 | nw lu n 8.8.8.8 -o yaml 113 | nw lu n dns.google. -o yaml 114 | 115 | `, 116 | Short: "Lookup hostnames, IPs, ISPs, nameservers, and networks.", 117 | Run: func(cmd *cobra.Command, args []string) { 118 | _ = cmd.Usage() 119 | }, 120 | } 121 | 122 | var lookupHostnameCmd = &cobra.Command{ 123 | Use: "hostname", 124 | Short: "Lookup the hostname for a provided ip address.", 125 | Aliases: []string{"hn"}, 126 | Example: ` 127 | # Lookup hostname by IP: 128 | 129 | networker lookup hostname 8.8.8.8 130 | 131 | # Lookup hostname by IP(short-hand): 132 | 133 | nw lu hn 8.8.8.8 134 | 135 | # Lookup hostname by IP(short-hand) and output as json: 136 | 137 | nw lu hn 8.8.8.8 -o json 138 | 139 | # Lookup hostname by IP(short-hand) and output as yaml: 140 | 141 | nw lu hn 8.8.8.8 -o yaml 142 | 143 | `, 144 | Args: cobra.ExactArgs(1), 145 | Run: func(cmd *cobra.Command, args []string) { 146 | ipAddr := net.ParseIP(args[0]) 147 | if ipAddr == nil { 148 | usage.Fatalf(cmd, "%q is not a valid ip address", args[0]) 149 | } 150 | enc := encoder.New[resolve.Record](os.Stdout, output) 151 | if err := enc.Encode(*resolve.HostNameByIP(ipAddr)); err != nil { 152 | usage.Fatalf(cmd, "failed to encode hostname record: %s", err) 153 | } 154 | }, 155 | } 156 | 157 | var lookupIpaddressCmd = &cobra.Command{ 158 | Use: "ip", 159 | Short: "Lookup the ip address of the provided hostname.", 160 | Example: ` 161 | # Lookup IP by hostname: 162 | 163 | networker lookup ip dns.google. 164 | 165 | # Lookup IP by hostname(short-hand): 166 | 167 | nw lu ip dns.google. 168 | 169 | # Lookup IP by hostname(short-hand) and output as json: 170 | 171 | nw lu ip dns.google. -o json 172 | 173 | # Lookup IP by hostname(short-hand) and output as yaml: 174 | 175 | nw lu ip dns.google. -o yaml 176 | 177 | `, 178 | Args: cobra.ExactArgs(1), 179 | Run: func(cmd *cobra.Command, args []string) { 180 | if ip := net.ParseIP(args[0]); ip != nil { 181 | usage.Fatal(cmd, "expected a hostname not an ip address") 182 | return 183 | } 184 | 185 | record, err := resolve.AddrByHostName(args[0]) 186 | if err != nil { 187 | usage.Fatalf(cmd, "lookup failed: %s", err) 188 | } 189 | 190 | enc := encoder.New[resolve.Record](os.Stdout, output) 191 | if err := enc.Encode(*record); err != nil { 192 | usage.Fatalf(cmd, "failed to encode ip address record: %s", err) 193 | } 194 | }, 195 | } 196 | 197 | var lookupIspCmd = &cobra.Command{ 198 | Use: "isp", 199 | Example: ` 200 | # Lookup ISP by ip or hostname: 201 | 202 | networker lookup isp 8.8.8.8 203 | networker lookup isp dns.google. 204 | 205 | # Lookup ISP by ip or hostname(short-hand): 206 | 207 | nw lu isp 8.8.8.8 208 | nw lu isp dns.google. 209 | 210 | # Lookup ISP by ip or hostname(short-hand) and output as json: 211 | 212 | nw lu isp 8.8.8.8 -o json 213 | nw lu isp dns.google. -o json 214 | 215 | # Lookup ISP by ip or hostname(short-hand) and output as yaml: 216 | 217 | nw lu isp 8.8.8.8 -o yaml 218 | nw lu isp dns.google. -o yaml 219 | `, 220 | Short: "Lookup the internet service provider of a remote host.", 221 | Args: cobra.ExactArgs(1), 222 | Run: func(cmd *cobra.Command, args []string) { 223 | _, ip, err := resolve.HostAndAddr(args[0]) 224 | if err != nil { 225 | usage.Fatalf(cmd, "%q is an invalid host: %s", args[0], err) 226 | } 227 | 228 | if resolve.IsPrivate(ip) { 229 | usage.Fatalf(cmd, "cannot retrieve internet service provider for private ip") 230 | } 231 | 232 | isp, err := resolve.ServiceProvider(ip) 233 | if err != nil { 234 | usage.Fatalf(cmd, "failed to resolve internet service provider for %q: %s", ip, err) 235 | } 236 | 237 | enc := encoder.New[resolve.InternetServiceProvider](os.Stdout, output) 238 | if err := enc.Encode(*isp); err != nil { 239 | usage.Fatalf(cmd, "failed to encode internet service provider: %s", err) 240 | } 241 | }, 242 | } 243 | 244 | var lookupNameserversCmd = &cobra.Command{ 245 | Use: "nameservers", 246 | Aliases: []string{"ns"}, 247 | Short: "Lookup nameservers for the provided hostname.", 248 | Example: ` 249 | # Lookup nameservers by hostname: 250 | 251 | networker lookup nameservers dns.google. 252 | 253 | # Lookup nameservers by hostname(short-hand): 254 | 255 | nw lu ns dns.google. 256 | 257 | # Lookup nameservers by hostname(short-hand) and output as json: 258 | 259 | nw lu ns dns.google. -o json 260 | 261 | # Lookup nameservers by hostname(short-hand) and output as yaml: 262 | 263 | nw lu ns dns.google. -o yaml 264 | `, 265 | Args: cobra.ExactArgs(1), 266 | Run: func(cmd *cobra.Command, args []string) { 267 | hostname, _, err := resolve.HostAndAddr(args[0]) 268 | if err != nil { 269 | usage.Fatalf(cmd, "%q is an invalid host: %s", args[0], err) 270 | } 271 | 272 | nameservers, err := resolve.NameServersByHostName(hostname) 273 | if err != nil { 274 | usage.Fatalf(cmd, "lookup failed: %s", err) 275 | } 276 | 277 | enc := encoder.New[resolve.NameServer](os.Stdout, output) 278 | if err := enc.Encode(nameservers...); err != nil { 279 | usage.Fatalf(cmd, "failed to encode nameservers: %s", err) 280 | } 281 | }, 282 | } 283 | 284 | var lookupNetworkCmd = &cobra.Command{ 285 | Use: "network", 286 | Short: "Lookup the network address of a provided host.", 287 | Example: ` 288 | # Lookup network by ip or hostname: 289 | 290 | networker lookup network 8.8.8.8 291 | networker lookup network dns.google. 292 | 293 | # Lookup network by ip or hostname(short-hand): 294 | 295 | nw lu n 8.8.8.8 296 | nw lu n dns.google. 297 | 298 | # Lookup network by ip or hostname(short-hand) and output as json: 299 | 300 | nw lu n 8.8.8.8 -o json 301 | nw lu n dns.google. -o json 302 | 303 | # Lookup network by ip or hostname(short-hand) and output as yaml: 304 | 305 | nw lu n 8.8.8.8 -o yaml 306 | nw lu n dns.google. -o yaml 307 | 308 | `, 309 | Args: cobra.ExactArgs(1), 310 | Aliases: []string{"n"}, 311 | Run: func(cmd *cobra.Command, args []string) { 312 | nwRecord, err := resolve.NetworkByHost(args[0]) 313 | if err != nil { 314 | usage.Fatalf(cmd, "lookup failed: %s", err) 315 | } 316 | 317 | enc := encoder.New[resolve.NetworkRecord](os.Stdout, output) 318 | if err := enc.Encode(*nwRecord); err != nil { 319 | usage.Fatalf(cmd, "failed to encode network record: %s", err) 320 | } 321 | }, 322 | } 323 | -------------------------------------------------------------------------------- /cmd/lookup_test.go: -------------------------------------------------------------------------------- 1 | package cmd 2 | 3 | import ( 4 | "encoding/json" 5 | "os/exec" 6 | "testing" 7 | 8 | "github.com/fuskovic/networker/v3/internal/resolve" 9 | "github.com/fuskovic/networker/v3/internal/test" 10 | "github.com/stretchr/testify/require" 11 | ) 12 | 13 | func TestLookupHostnameCommand(t *testing.T) { 14 | t.Run("ShouldPass", func(t *testing.T) { 15 | test.WithNetworker(t, "lookup hostname", func(t *testing.T) { 16 | cmd := exec.Command("networker", "lookup", "hostname", "8.8.8.8") 17 | output, err := cmd.CombinedOutput() 18 | require.NoError(t, err) 19 | require.Contains(t, string(output), "dns.google.") 20 | }) 21 | test.WithNetworker(t, "lookup hostname output as json", func(t *testing.T) { 22 | cmd := exec.Command("networker", "lookup", "hostname", "8.8.8.8", "-o", "json") 23 | output, err := cmd.CombinedOutput() 24 | require.NoError(t, err) 25 | record := new(resolve.Record) 26 | require.NoError(t, json.Unmarshal(output, record)) 27 | require.Equal(t, "dns.google.", record.Hostname) 28 | 29 | }) 30 | test.WithNetworker(t, "lookup hostname output as yaml", func(t *testing.T) { 31 | cmd := exec.Command("networker", "lookup", "hostname", "8.8.8.8", "-o", "yaml") 32 | output, err := cmd.CombinedOutput() 33 | require.NoError(t, err) 34 | require.Contains(t, string(output), "- hostname: dns.google.") 35 | }) 36 | }) 37 | t.Run("ShouldFail", func(t *testing.T) { 38 | test.WithNetworker(t, "lookup hostname no ip address provided", func(t *testing.T) { 39 | cmd := exec.Command("networker", "lookup", "hostname") 40 | output, _ := cmd.CombinedOutput() 41 | require.Contains(t, string(output), "Error: accepts 1 arg(s), received 0") 42 | }) 43 | test.WithNetworker(t, "lookup hostname invalid ip address", func(t *testing.T) { 44 | cmd := exec.Command("networker", "lookup", "hostname", "invalid") 45 | output, _ := cmd.CombinedOutput() 46 | require.Contains(t, string(output), "not a valid ip address") 47 | }) 48 | }) 49 | } 50 | 51 | func TestLookupIpAddressCommand(t *testing.T) { 52 | t.Run("ShouldPass", func(t *testing.T) { 53 | test.WithNetworker(t, "lookup ip", func(t *testing.T) { 54 | cmd := exec.Command("networker", "lookup", "ip", "dns.google.") 55 | output, err := cmd.CombinedOutput() 56 | require.NoError(t, err) 57 | require.Contains(t, string(output), "8.8.") 58 | }) 59 | test.WithNetworker(t, "lookup ip output as json", func(t *testing.T) { 60 | cmd := exec.Command("networker", "lookup", "ip", "dns.google.", "-o", "json") 61 | output, err := cmd.CombinedOutput() 62 | require.NoError(t, err) 63 | record := new(resolve.Record) 64 | require.NoError(t, json.Unmarshal(output, record)) 65 | require.Equal(t, "dns.google.", record.Hostname) 66 | 67 | }) 68 | test.WithNetworker(t, "lookup ip output as yaml", func(t *testing.T) { 69 | cmd := exec.Command("networker", "lookup", "ip", "dns.google.", "-o", "yaml") 70 | output, err := cmd.CombinedOutput() 71 | require.NoError(t, err) 72 | require.Contains(t, string(output), "- hostname: dns.google.") 73 | }) 74 | }) 75 | t.Run("ShouldFail", func(t *testing.T) { 76 | test.WithNetworker(t, "lookup ip address hostname not provided", func(t *testing.T) { 77 | cmd := exec.Command("networker", "lookup", "ip") 78 | output, _ := cmd.CombinedOutput() 79 | require.Contains(t, string(output), "Error: accepts 1 arg(s), received 0") 80 | }) 81 | test.WithNetworker(t, "lookup ip address but ip provided instead of hostname", func(t *testing.T) { 82 | cmd := exec.Command("networker", "lookup", "ip", "8.8.8.8") 83 | output, _ := cmd.CombinedOutput() 84 | require.Contains(t, string(output), `expected a hostname not an ip address`) 85 | }) 86 | }) 87 | } 88 | 89 | func TestLookupIspCommand(t *testing.T) { 90 | t.Run("ShouldPass", func(t *testing.T) { 91 | test.WithNetworker(t, "lookup isp with hostname", func(t *testing.T) { 92 | cmd := exec.Command("networker", "lookup", "isp", "dns.google.") 93 | output, err := cmd.CombinedOutput() 94 | require.NoError(t, err) 95 | require.Contains(t, string(output), "GOOGLE, US") 96 | }) 97 | test.WithNetworker(t, "lookup isp with hostname output as json output", func(t *testing.T) { 98 | cmd := exec.Command("networker", "lookup", "isp", "dns.google.", "-o", "json") 99 | output, err := cmd.CombinedOutput() 100 | require.NoError(t, err) 101 | isp := new(resolve.InternetServiceProvider) 102 | require.NoError(t, json.Unmarshal(output, isp)) 103 | }) 104 | test.WithNetworker(t, "lookup isp with hostname output as yaml output", func(t *testing.T) { 105 | cmd := exec.Command("networker", "lookup", "isp", "dns.google.", "-o", "yaml") 106 | output, err := cmd.CombinedOutput() 107 | require.NoError(t, err) 108 | require.Contains(t, string(output), "- name: GOOGLE, US") 109 | }) 110 | test.WithNetworker(t, "lookup isp with ip address", func(t *testing.T) { 111 | cmd := exec.Command("networker", "lookup", "isp", "8.8.8.8") 112 | output, err := cmd.CombinedOutput() 113 | require.NoError(t, err) 114 | require.Contains(t, string(output), "GOOGLE, US") 115 | }) 116 | test.WithNetworker(t, "lookup isp with ip address output as json output", func(t *testing.T) { 117 | cmd := exec.Command("networker", "lookup", "isp", "8.8.8.8", "-o", "json") 118 | output, err := cmd.CombinedOutput() 119 | require.NoError(t, err) 120 | isp := new(resolve.InternetServiceProvider) 121 | require.NoError(t, json.Unmarshal(output, isp)) 122 | }) 123 | test.WithNetworker(t, "lookup isp with ip address output as yaml output", func(t *testing.T) { 124 | cmd := exec.Command("networker", "lookup", "isp", "8.8.8.8", "-o", "yaml") 125 | output, err := cmd.CombinedOutput() 126 | require.NoError(t, err) 127 | require.Contains(t, string(output), "- name: GOOGLE, US") 128 | }) 129 | }) 130 | t.Run("ShouldFail", func(t *testing.T) { 131 | test.WithNetworker(t, "lookup isp no host provided", func(t *testing.T) { 132 | cmd := exec.Command("networker", "lookup", "isp") 133 | output, _ := cmd.CombinedOutput() 134 | require.Contains(t, string(output), "Error: accepts 1 arg(s), received 0") 135 | }) 136 | test.WithNetworker(t, "lookup isp for private ip address", func(t *testing.T) { 137 | cmd := exec.Command("networker", "lookup", "isp", "127.0.0.1") 138 | output, err := cmd.CombinedOutput() 139 | require.Error(t, err) 140 | require.Contains(t, string(output), "cannot retrieve internet service provider for private ip") 141 | }) 142 | }) 143 | } 144 | 145 | func TestLookupNetworkCommand(t *testing.T) { 146 | t.Run("ShouldPass", func(t *testing.T) { 147 | test.WithNetworker(t, "lookup network with hostname", func(t *testing.T) { 148 | cmd := exec.Command("networker", "lookup", "network", "dns.google.") 149 | output, err := cmd.CombinedOutput() 150 | require.NoError(t, err) 151 | require.Contains(t, string(output), "8.0.0.0") 152 | }) 153 | test.WithNetworker(t, "lookup network with hostname output as json", func(t *testing.T) { 154 | cmd := exec.Command("networker", "lookup", "network", "dns.google.", "-o", "json") 155 | output, err := cmd.CombinedOutput() 156 | require.NoError(t, err) 157 | record := new(resolve.NetworkRecord) 158 | require.NoError(t, err, json.Unmarshal(output, &record)) 159 | require.Equal(t, "8.0.0.0", record.NetworkIP.String()) 160 | }) 161 | test.WithNetworker(t, "lookup network with hostname output as yaml", func(t *testing.T) { 162 | cmd := exec.Command("networker", "lookup", "network", "dns.google.", "-o", "yaml") 163 | output, err := cmd.CombinedOutput() 164 | require.NoError(t, err) 165 | require.Contains(t, string(output), "network: 8.0.0.0") 166 | }) 167 | test.WithNetworker(t, "lookup network with ip", func(t *testing.T) { 168 | cmd := exec.Command("networker", "lookup", "network", "8.8.8.8") 169 | output, err := cmd.CombinedOutput() 170 | require.NoError(t, err) 171 | require.Contains(t, string(output), "8.0.0.0") 172 | }) 173 | test.WithNetworker(t, "lookup network with ip output as json", func(t *testing.T) { 174 | cmd := exec.Command("networker", "lookup", "network", "8.8.8.8", "-o", "json") 175 | output, err := cmd.CombinedOutput() 176 | require.NoError(t, err) 177 | record := new(resolve.NetworkRecord) 178 | require.NoError(t, err, json.Unmarshal(output, &record)) 179 | require.Equal(t, "8.0.0.0", record.NetworkIP.String()) 180 | }) 181 | test.WithNetworker(t, "lookup network with ip output as yaml", func(t *testing.T) { 182 | cmd := exec.Command("networker", "lookup", "network", "8.8.8.8", "-o", "yaml") 183 | output, err := cmd.CombinedOutput() 184 | require.NoError(t, err) 185 | require.Contains(t, string(output), "network: 8.0.0.0") 186 | }) 187 | }) 188 | t.Run("ShouldFail", func(t *testing.T) { 189 | test.WithNetworker(t, "lookup network no arg provided", func(t *testing.T) { 190 | cmd := exec.Command("networker", "lookup", "network") 191 | output, _ := cmd.CombinedOutput() 192 | require.Contains(t, string(output), "Error: accepts 1 arg(s), received 0") 193 | }) 194 | test.WithNetworker(t, "lookup network invalid arg", func(t *testing.T) { 195 | cmd := exec.Command("networker", "lookup", "network", "invalid") 196 | output, _ := cmd.CombinedOutput() 197 | require.Contains(t, string(output), "invalild host") 198 | }) 199 | }) 200 | } 201 | 202 | func TestLookupNameserversCommand(t *testing.T) { 203 | t.Run("ShouldPass", func(t *testing.T) { 204 | test.WithNetworker(t, "lookup nameservers with hostname", func(t *testing.T) { 205 | cmd := exec.Command("networker", "lookup", "nameservers", "dns.google.") 206 | output, err := cmd.CombinedOutput() 207 | require.NoError(t, err) 208 | require.Contains(t, string(output), "ns1.zdns.google.") 209 | }) 210 | test.WithNetworker(t, "lookup nameservers with hostname output as json", func(t *testing.T) { 211 | cmd := exec.Command("networker", "lookup", "nameservers", "dns.google.", "-o", "json") 212 | output, err := cmd.CombinedOutput() 213 | require.NoError(t, err) 214 | var nameservers []resolve.NameServer 215 | require.NoError(t, err, json.Unmarshal(output, &nameservers)) 216 | require.False(t, len(nameservers) == 0) 217 | }) 218 | test.WithNetworker(t, "lookup nameservers with hostname output as yaml", func(t *testing.T) { 219 | cmd := exec.Command("networker", "lookup", "nameservers", "dns.google.", "-o", "yaml") 220 | output, err := cmd.CombinedOutput() 221 | require.NoError(t, err) 222 | require.Contains(t, string(output), "host: ns1.zdns.google.") 223 | }) 224 | test.WithNetworker(t, "lookup nameservers with ip", func(t *testing.T) { 225 | cmd := exec.Command("networker", "lookup", "nameservers", "8.8.8.8") 226 | output, err := cmd.CombinedOutput() 227 | require.NoError(t, err) 228 | require.Contains(t, string(output), "ns1.zdns.google.") 229 | }) 230 | test.WithNetworker(t, "lookup nameservers with ip output as json", func(t *testing.T) { 231 | cmd := exec.Command("networker", "lookup", "nameservers", "8.8.8.8", "-o", "json") 232 | output, err := cmd.CombinedOutput() 233 | require.NoError(t, err) 234 | var nameservers []resolve.NameServer 235 | require.NoError(t, err, json.Unmarshal(output, &nameservers)) 236 | require.False(t, len(nameservers) == 0) 237 | }) 238 | test.WithNetworker(t, "lookup nameservers with ip output as yaml", func(t *testing.T) { 239 | cmd := exec.Command("networker", "lookup", "nameservers", "8.8.8.8", "-o", "yaml") 240 | output, err := cmd.CombinedOutput() 241 | require.NoError(t, err) 242 | require.Contains(t, string(output), "host: ns1.zdns.google.") 243 | }) 244 | }) 245 | t.Run("ShouldFail", func(t *testing.T) { 246 | test.WithNetworker(t, "lookup nameservers hostname not provided", func(t *testing.T) { 247 | cmd := exec.Command("networker", "lookup", "nameservers") 248 | output, _ := cmd.CombinedOutput() 249 | require.Contains(t, string(output), "Error: accepts 1 arg(s), received 0") 250 | }) 251 | test.WithNetworker(t, "lookup nameservers hostname doesnt exist", func(t *testing.T) { 252 | cmd := exec.Command("networker", "lookup", "nameservers", "doesntexist") 253 | output, err := cmd.CombinedOutput() 254 | require.Error(t, err) 255 | require.Contains(t, string(output), "lookup failed") 256 | }) 257 | test.WithNetworker(t, "lookup network no host provided", func(t *testing.T) { 258 | cmd := exec.Command("networker", "lookup", "network") 259 | output, _ := cmd.CombinedOutput() 260 | require.Contains(t, string(output), "Error: accepts 1 arg(s), received 0") 261 | }) 262 | }) 263 | } 264 | -------------------------------------------------------------------------------- /cmd/root.go: -------------------------------------------------------------------------------- 1 | package cmd 2 | 3 | import ( 4 | _ "embed" 5 | 6 | "github.com/spf13/cobra" 7 | ) 8 | 9 | var ( 10 | //go:embed version.txt 11 | version string 12 | output string 13 | shouldOutputVersion bool 14 | ) 15 | 16 | func init() { 17 | Root.PersistentFlags().StringVarP(&output, "output", "o", output, "Output format. Supported values include json and yaml.") 18 | Root.Flags().BoolVarP(&shouldOutputVersion, "version", "v", false, "Print installed version.") 19 | } 20 | 21 | var Root = &cobra.Command{ 22 | Use: "networker", 23 | Aliases: []string{"nw"}, 24 | Short: "A simple networking utility.", 25 | Args: cobra.NoArgs, 26 | Run: func(cmd *cobra.Command, args []string) { 27 | if shouldOutputVersion { 28 | println(version) 29 | return 30 | } 31 | _ = cmd.Usage() 32 | }, 33 | } 34 | -------------------------------------------------------------------------------- /cmd/scan.go: -------------------------------------------------------------------------------- 1 | package cmd 2 | 3 | import ( 4 | "context" 5 | "net" 6 | "os" 7 | "slices" 8 | 9 | "github.com/spf13/cobra" 10 | 11 | "github.com/fuskovic/networker/v3/internal/encoder" 12 | "github.com/fuskovic/networker/v3/internal/list" 13 | "github.com/fuskovic/networker/v3/internal/resolve" 14 | "github.com/fuskovic/networker/v3/internal/scanner" 15 | "github.com/fuskovic/networker/v3/internal/spinner" 16 | "github.com/fuskovic/networker/v3/internal/usage" 17 | ) 18 | 19 | var scanAllPorts bool 20 | 21 | func init() { 22 | scanCmd.Flags().BoolVar(&scanAllPorts, "all-ports", false, "Scan all ports(scans first 1024 if not enabled).") 23 | Root.AddCommand(scanCmd) 24 | } 25 | 26 | var scanCmd = &cobra.Command{ 27 | Use: "scan", 28 | Aliases: []string{"s"}, 29 | Short: "Scan hosts for open ports.", 30 | Example: ` 31 | # Scan well-known ports(first 1024) of all devices on network: 32 | 33 | networker scan 34 | 35 | # Scan well-known ports(first 1024) of all devices on network(short-hand): 36 | 37 | nw s 38 | 39 | # Scan well-known ports(first 1024) of all devices on network(short-hand) and output as json: 40 | 41 | nw s -o json 42 | 43 | # Scan well-known ports(first 1024) of all devices on network(short-hand) and output as yaml: 44 | 45 | nw s -o yaml 46 | 47 | # Scan all ports of all devices on network: 48 | 49 | networker scan --all-ports 50 | 51 | # Scan all ports of all devices on network(short-hand): 52 | 53 | nw s --all-ports 54 | 55 | # Scan all ports of all devices on network(short-hand) and output as json: 56 | 57 | nw s -o json --all-ports 58 | 59 | # Scan all ports of all devices on network(short-hand) and output as yaml: 60 | 61 | nw s -o yaml --all-ports 62 | 63 | # Scan well-known ports(first 1024) of single host: 64 | 65 | networker scan localhost 66 | 67 | # Scan well-known ports(first 1024) of single host(short-hand): 68 | 69 | nw s localhost 70 | 71 | # Scan well-known ports(first 1024) of single host(short-hand) and output as json: 72 | 73 | nw s localhost -o json 74 | 75 | # Scan well-known ports(first 1024) of single host(short-hand) and output as yaml: 76 | 77 | nw s localhost -o yaml 78 | 79 | # Scan all ports of single host: 80 | 81 | networker scan localhost --all-ports 82 | 83 | # Scan all ports of single host(short-hand): 84 | 85 | nw s localhost --all-ports 86 | 87 | # Scan all ports of single host(short-hand) and output as json: 88 | 89 | nw s localhost -o json --all-ports 90 | 91 | # Scan all ports of single host(short-hand) and output as yaml: 92 | 93 | nw s localhost -o yaml --all-ports 94 | 95 | `, 96 | Args: cobra.MaximumNArgs(1), 97 | Run: func(cmd *cobra.Command, args []string) { 98 | ctx, cancel := context.WithCancel(context.Background()) 99 | defer cancel() 100 | 101 | var hosts []string 102 | if len(args) == 0 { 103 | devices, err := list.Devices(ctx) 104 | if err != nil { 105 | usage.Fatalf(cmd, "failed to list network devices: %s", err) 106 | } 107 | for i := range devices { 108 | hosts = append(hosts, devices[i].LocalIP.String()) 109 | } 110 | } else { 111 | ip := net.ParseIP(args[0]) 112 | if ip == nil { 113 | record, err := resolve.AddrByHostName(args[0]) 114 | if err != nil { 115 | usage.Fatalf(cmd, "failed to resolve ip address from hostname: %s", err) 116 | } 117 | ip = record.IP 118 | } 119 | hosts = append(hosts, ip.String()) 120 | } 121 | 122 | spinner.Start() 123 | 124 | scans, err := scanner.New(hosts, scanAllPorts).Scan(ctx) 125 | if err != nil { 126 | usage.Fatalf(cmd, "failed scan hosts: %s", err) 127 | } 128 | 129 | spinner.Stop() 130 | 131 | scans = slices.DeleteFunc(scans, 132 | func(s scanner.Scan) bool { 133 | return s.Host == "N/A" && len(s.Ports) == 0 134 | }, 135 | ) 136 | 137 | enc := encoder.New[scanner.Scan](os.Stdout, output) 138 | if err := enc.Encode(scans...); err != nil { 139 | usage.Fatalf(cmd, "failed to encode devices: %s", err) 140 | } 141 | }, 142 | } 143 | -------------------------------------------------------------------------------- /cmd/scan_test.go: -------------------------------------------------------------------------------- 1 | package cmd 2 | 3 | import ( 4 | "encoding/json" 5 | "os/exec" 6 | "testing" 7 | 8 | "github.com/fuskovic/networker/v3/internal/scanner" 9 | "github.com/fuskovic/networker/v3/internal/test" 10 | "github.com/stretchr/testify/require" 11 | ) 12 | 13 | func TestScanCommand(t *testing.T) { 14 | test.WithNetworker(t, "output scanned devices as json", func(t *testing.T) { 15 | // start the list command 16 | cmd := exec.Command("networker", "scan", "-o", "json") 17 | stdout, err := cmd.StdoutPipe() 18 | require.NoError(t, err) 19 | require.NoError(t, cmd.Start()) 20 | 21 | // assert we can unmarshal the json output as expected 22 | var scanResults []scanner.Scan 23 | require.NoError(t, json.NewDecoder(stdout).Decode(&scanResults)) 24 | require.NoError(t, cmd.Wait()) 25 | 26 | // assert that the results are not empty 27 | require.True(t, len(scanResults) > 0) 28 | }) 29 | test.WithNetworker(t, "output scanned devices as yaml", func(t *testing.T) { 30 | // start the list command 31 | cmd := exec.Command("networker", "scan", "-o", "json") 32 | stdout, err := cmd.StdoutPipe() 33 | require.NoError(t, err) 34 | require.NoError(t, cmd.Start()) 35 | 36 | // assert we can unmarshal the json output as expected 37 | var scanResults []scanner.Scan 38 | require.NoError(t, json.NewDecoder(stdout).Decode(&scanResults)) 39 | require.NoError(t, cmd.Wait()) 40 | 41 | // assert that the results are not empty 42 | require.True(t, len(scanResults) > 0) 43 | }) 44 | } 45 | -------------------------------------------------------------------------------- /cmd/shell.go: -------------------------------------------------------------------------------- 1 | package cmd 2 | 3 | import ( 4 | "net" 5 | "runtime" 6 | "strings" 7 | 8 | "github.com/spf13/cobra" 9 | 10 | "github.com/fuskovic/networker/v3/internal/shell" 11 | "github.com/fuskovic/networker/v3/internal/usage" 12 | ) 13 | 14 | var port int 15 | 16 | func init() { 17 | serveCmd.Flags().IntVarP(&port, "port", "p", 4444, "Port to serve shell on.") 18 | shellCmd.AddCommand(serveCmd) 19 | shellCmd.AddCommand(dialCmd) 20 | Root.AddCommand(shellCmd) 21 | } 22 | 23 | var shellCmd = &cobra.Command{ 24 | Use: "shell", 25 | Short: "Serve and establish connections with remote shells.", 26 | Example: ` 27 | # Serve using the defaults(bash is the default shell and 4444 is the default port): 28 | 29 | nw shell serve 30 | 31 | # Serve a particular shell on a particular port: 32 | 33 | nw shell serve zsh --port 9000 34 | 35 | # Establish a new shell session by dialing a networker initiated shell server. 36 | 37 | nw shell dial some.remote.ip.addr:9000 38 | 39 | `, 40 | Args: cobra.NoArgs, 41 | Run: func(cmd *cobra.Command, args []string) { 42 | _ = cmd.Usage() 43 | }, 44 | } 45 | 46 | var serveCmd = &cobra.Command{ 47 | Use: "serve", 48 | Short: "Start a shell server.", 49 | Example: ` 50 | # Serve using the defaults(bash is the default shell and 4444 is the default port): 51 | 52 | nw shell serve 53 | 54 | # Serve a particular shell on a particular port: 55 | 56 | nw shell serve zsh -p 9000 57 | 58 | `, 59 | Args: cobra.MaximumNArgs(1), 60 | Run: func(cmd *cobra.Command, args []string) { 61 | if runtime.GOOS == "windows" { 62 | usage.Fatal(cmd, "this command is not supported on windows") 63 | } 64 | 65 | sh := "bash" 66 | if len(args) == 1 { 67 | sh = strings.Replace(args[0], "/bin/", "", 1) 68 | } 69 | 70 | if err := shell.Serve(sh, port); err != nil { 71 | usage.Fatalf(cmd, "unexpected server shutdown: %s\n", err) 72 | } 73 | }, 74 | } 75 | 76 | var dialCmd = &cobra.Command{ 77 | Use: "dial", 78 | Short: "Dial a shell server.", 79 | Example: ` 80 | # Establish a new shell session by dialing a networker initiated shell server. 81 | 82 | nw shell dial some.remote.ip.addr:9000 83 | 84 | `, 85 | Args: cobra.ExactArgs(1), 86 | Run: func(cmd *cobra.Command, args []string) { 87 | if _, _, err := net.SplitHostPort(args[0]); err != nil { 88 | usage.Fatalf(cmd, "invalid address: %s\n", err) 89 | } 90 | 91 | if err := shell.Dial(args[0]); err != nil { 92 | usage.Fatalf(cmd, "dialer error: %s\n", err) 93 | } 94 | }, 95 | } 96 | -------------------------------------------------------------------------------- /cmd/shell_test.go: -------------------------------------------------------------------------------- 1 | package cmd 2 | 3 | import ( 4 | "net" 5 | "os/exec" 6 | "strconv" 7 | "strings" 8 | "testing" 9 | "time" 10 | 11 | "github.com/fuskovic/networker/v3/internal/test" 12 | "github.com/stretchr/testify/require" 13 | ) 14 | 15 | func TestServeCommand(t *testing.T) { 16 | t.Run("ShouldFail", func(t *testing.T) { 17 | test.WithNetworker(t, "if shell is unsupported", func(t *testing.T) { 18 | cmd := exec.Command("networker", "shell", "serve", "unsupported") 19 | output, err := cmd.CombinedOutput() 20 | require.Error(t, err) 21 | require.Contains(t, string(output), "shell \"unsupported\" is not supported") 22 | }) 23 | test.WithNetworker(t, "if shell is not installed", func(t *testing.T) { 24 | cmd := exec.Command("networker", "shell", "serve", "fish") 25 | output, err := cmd.CombinedOutput() 26 | require.Error(t, err) 27 | require.Contains(t, 28 | string(output), 29 | "shell \"fish\" does not exist on system: exec: \"fish\": executable file not found in $PATH", 30 | ) 31 | }) 32 | test.WithNetworker(t, "if port is invalid", func(t *testing.T) { 33 | cmd := exec.Command("networker", "shell", "serve", "-p", "70000") 34 | output, err := cmd.CombinedOutput() 35 | require.Error(t, err) 36 | require.Contains(t, string(output), "not a valid port") 37 | }) 38 | }) 39 | t.Run("ShouldPass", func(t *testing.T) { 40 | test.WithNetworker(t, "if args are valid", func(t *testing.T) { 41 | t.Skip() 42 | cmd := exec.Command("networker", "shell", "serve", "-p", "2222") 43 | require.NoError(t, cmd.Start()) 44 | 45 | // validate that the server is up 46 | conn, err := net.DialTimeout("tcp", "localhost:2222", 3*time.Second) 47 | require.NoError(t, err) 48 | 49 | // close the client connection 50 | require.NoError(t, conn.Close()) 51 | }) 52 | }) 53 | } 54 | 55 | func TestDialCommand(t *testing.T) { 56 | t.Run("ShouldFail", func(t *testing.T) { 57 | test.WithNetworker(t, "if target addr is not serving shell", func(t *testing.T) { 58 | cmd := exec.Command("networker", "shell", "dial", "localhost:9000") 59 | output, err := cmd.CombinedOutput() 60 | require.Error(t, err) 61 | require.Contains(t, string(output), "connect: connection refused") 62 | }) 63 | }) 64 | t.Run("ShouldPass", func(t *testing.T) { 65 | test.WithNetworker(t, "if dialing active shell server with valid args", func(t *testing.T) { 66 | cmd := exec.Command("networker", "shell", "serve", "-p", "8000") 67 | require.NoError(t, cmd.Start()) 68 | 69 | // validate that the server is up 70 | conn, err := net.DialTimeout("tcp", "localhost:8000", 3*time.Second) 71 | require.NoError(t, err) 72 | 73 | // close the client connection 74 | require.NoError(t, conn.Close()) 75 | 76 | // get the process id of the current shell 77 | getShellPid := exec.Command("bash", "-c", "echo $$") 78 | output, err := getShellPid.CombinedOutput() 79 | require.NoError(t, err) 80 | out := strings.TrimSpace(string(output)) 81 | ogPid, err := strconv.Atoi(out) 82 | require.NoError(t, err) 83 | t.Logf("og_pid: %d\n", ogPid) 84 | 85 | // dial it using the dial subcommand 86 | cmd = exec.Command("networker", "shell", "dial", "localhost:8000") 87 | require.NoError(t, cmd.Start()) 88 | 89 | // grace period to wait for connection to establish 90 | time.Sleep(time.Second) 91 | 92 | // get the process id of the new shell 93 | getShellPid = exec.Command("bash", "-c", "echo $$") 94 | output, err = getShellPid.CombinedOutput() 95 | require.NoError(t, err) 96 | out = strings.TrimSpace(string(output)) 97 | remotePid, err := strconv.Atoi(out) 98 | require.NoError(t, err) 99 | t.Logf("remote_pid: %d\n", remotePid) 100 | 101 | // assert that the current shells process id is different than the original 102 | require.NotEqual(t, ogPid, remotePid) 103 | 104 | // kill the client connection by exiting the remote shell 105 | exitCmd := exec.Command("bash", "-c", "exit") 106 | require.NoError(t, exitCmd.Run()) 107 | }) 108 | }) 109 | } 110 | -------------------------------------------------------------------------------- /cmd/version.txt: -------------------------------------------------------------------------------- 1 | v3.1.3 2 | -------------------------------------------------------------------------------- /docs/networker.md: -------------------------------------------------------------------------------- 1 | ## networker 2 | 3 | A simple networking utility. 4 | 5 | ``` 6 | networker [flags] 7 | ``` 8 | 9 | ### Options 10 | 11 | ``` 12 | -h, --help help for networker 13 | -o, --output string Output format. Supported values include json and yaml. 14 | -v, --version Print installed version. 15 | ``` 16 | 17 | ### SEE ALSO 18 | 19 | * [networker list](networker_list.md) - List information on connected network devices. 20 | * [networker lookup](networker_lookup.md) - Lookup hostnames, IPs, ISPs, nameservers, and networks. 21 | * [networker scan](networker_scan.md) - Scan hosts for open ports. 22 | * [networker shell](networker_shell.md) - Serve and establish connections with remote shells. 23 | 24 | ###### Auto generated by spf13/cobra on 1-Jul-2023 25 | -------------------------------------------------------------------------------- /docs/networker_list.md: -------------------------------------------------------------------------------- 1 | ## networker list 2 | 3 | List information on connected network devices. 4 | 5 | ``` 6 | networker list [flags] 7 | ``` 8 | 9 | ### Examples 10 | 11 | ``` 12 | 13 | # List devices on network: 14 | 15 | networker list 16 | 17 | # List devices on network(short-hand): 18 | 19 | nw ls 20 | 21 | # List devices on network(short-hand) and output as json: 22 | 23 | nw ls -o json 24 | 25 | # List devices on network(short-hand) and output as yaml: 26 | 27 | nw ls -o yaml 28 | 29 | ``` 30 | 31 | ### Options 32 | 33 | ``` 34 | -h, --help help for list 35 | ``` 36 | 37 | ### Options inherited from parent commands 38 | 39 | ``` 40 | -o, --output string Output format. Supported values include json and yaml. 41 | ``` 42 | 43 | ### SEE ALSO 44 | 45 | * [networker](networker.md) - A simple networking utility. 46 | 47 | ###### Auto generated by spf13/cobra on 1-Jul-2023 48 | -------------------------------------------------------------------------------- /docs/networker_lookup.md: -------------------------------------------------------------------------------- 1 | ## networker lookup 2 | 3 | Lookup hostnames, IPs, ISPs, nameservers, and networks. 4 | 5 | ``` 6 | networker lookup [flags] 7 | ``` 8 | 9 | ### Examples 10 | 11 | ``` 12 | 13 | # Lookup hostname by IP: 14 | 15 | networker lookup hostname 8.8.8.8 16 | 17 | # Lookup hostname by IP(short-hand): 18 | 19 | nw lu hn 8.8.8.8 20 | 21 | # Lookup hostname by IP(short-hand) and output as json: 22 | 23 | nw lu hn 8.8.8.8 -o json 24 | 25 | # Lookup hostname by IP(short-hand) and output as yaml: 26 | 27 | nw lu hn 8.8.8.8 -o yaml 28 | 29 | # Lookup IP by hostname: 30 | 31 | networker lookup ip dns.google. 32 | 33 | # Lookup IP by hostname(short-hand): 34 | 35 | nw lu ip dns.google. 36 | 37 | # Lookup IP by hostname(short-hand) and output as json: 38 | 39 | nw lu ip dns.google. -o json 40 | 41 | # Lookup IP by hostname(short-hand) and output as yaml: 42 | 43 | nw lu ip dns.google. -o yaml 44 | 45 | # Lookup nameservers by hostname: 46 | 47 | networker lookup nameservers dns.google. 48 | 49 | # Lookup nameservers by hostname(short-hand): 50 | 51 | nw lu ns dns.google. 52 | 53 | # Lookup nameservers by hostname(short-hand) and output as json: 54 | 55 | nw lu ns dns.google. -o json 56 | 57 | # Lookup nameservers by hostname(short-hand) and output as yaml: 58 | 59 | nw lu ns dns.google. -o yaml 60 | 61 | # Lookup ISP by ip or hostname: 62 | 63 | networker lookup isp 8.8.8.8 64 | networker lookup isp dns.google. 65 | 66 | # Lookup ISP by ip or hostname(short-hand): 67 | 68 | nw lu isp 8.8.8.8 69 | nw lu isp dns.google. 70 | 71 | # Lookup ISP by ip or hostname(short-hand) and output as json: 72 | 73 | nw lu isp 8.8.8.8 -o json 74 | nw lu isp dns.google. -o json 75 | 76 | # Lookup ISP by ip or hostname(short-hand) and output as yaml: 77 | 78 | nw lu isp 8.8.8.8 -o yaml 79 | nw lu isp dns.google. -o yaml 80 | 81 | # Lookup network by ip or hostname: 82 | 83 | networker lookup network 8.8.8.8 84 | networker lookup network dns.google. 85 | 86 | # Lookup network by ip or hostname(short-hand): 87 | 88 | nw lu n 8.8.8.8 89 | nw lu n dns.google. 90 | 91 | # Lookup network by ip or hostname(short-hand) and output as json: 92 | 93 | nw lu n 8.8.8.8 -o json 94 | nw lu n dns.google. -o json 95 | 96 | # Lookup network by ip or hostname(short-hand) and output as yaml: 97 | 98 | nw lu n 8.8.8.8 -o yaml 99 | nw lu n dns.google. -o yaml 100 | 101 | 102 | ``` 103 | 104 | ### Options 105 | 106 | ``` 107 | -h, --help help for lookup 108 | ``` 109 | 110 | ### Options inherited from parent commands 111 | 112 | ``` 113 | -o, --output string Output format. Supported values include json and yaml. 114 | ``` 115 | 116 | ### SEE ALSO 117 | 118 | * [networker](networker.md) - A simple networking utility. 119 | * [networker lookup hostname](networker_lookup_hostname.md) - Lookup the hostname for a provided ip address. 120 | * [networker lookup ip](networker_lookup_ip.md) - Lookup the ip address of the provided hostname. 121 | * [networker lookup isp](networker_lookup_isp.md) - Lookup the internet service provider of a remote host. 122 | * [networker lookup nameservers](networker_lookup_nameservers.md) - Lookup nameservers for the provided hostname. 123 | * [networker lookup network](networker_lookup_network.md) - Lookup the network address of a provided host. 124 | 125 | ###### Auto generated by spf13/cobra on 1-Jul-2023 126 | -------------------------------------------------------------------------------- /docs/networker_lookup_hostname.md: -------------------------------------------------------------------------------- 1 | ## networker lookup hostname 2 | 3 | Lookup the hostname for a provided ip address. 4 | 5 | ``` 6 | networker lookup hostname [flags] 7 | ``` 8 | 9 | ### Examples 10 | 11 | ``` 12 | 13 | # Lookup hostname by IP: 14 | 15 | networker lookup hostname 8.8.8.8 16 | 17 | # Lookup hostname by IP(short-hand): 18 | 19 | nw lu hn 8.8.8.8 20 | 21 | # Lookup hostname by IP(short-hand) and output as json: 22 | 23 | nw lu hn 8.8.8.8 -o json 24 | 25 | # Lookup hostname by IP(short-hand) and output as yaml: 26 | 27 | nw lu hn 8.8.8.8 -o yaml 28 | 29 | 30 | ``` 31 | 32 | ### Options 33 | 34 | ``` 35 | -h, --help help for hostname 36 | ``` 37 | 38 | ### Options inherited from parent commands 39 | 40 | ``` 41 | -o, --output string Output format. Supported values include json and yaml. 42 | ``` 43 | 44 | ### SEE ALSO 45 | 46 | * [networker lookup](networker_lookup.md) - Lookup hostnames, IPs, ISPs, nameservers, and networks. 47 | 48 | ###### Auto generated by spf13/cobra on 1-Jul-2023 49 | -------------------------------------------------------------------------------- /docs/networker_lookup_ip.md: -------------------------------------------------------------------------------- 1 | ## networker lookup ip 2 | 3 | Lookup the ip address of the provided hostname. 4 | 5 | ``` 6 | networker lookup ip [flags] 7 | ``` 8 | 9 | ### Examples 10 | 11 | ``` 12 | 13 | # Lookup IP by hostname: 14 | 15 | networker lookup ip dns.google. 16 | 17 | # Lookup IP by hostname(short-hand): 18 | 19 | nw lu ip dns.google. 20 | 21 | # Lookup IP by hostname(short-hand) and output as json: 22 | 23 | nw lu ip dns.google. -o json 24 | 25 | # Lookup IP by hostname(short-hand) and output as yaml: 26 | 27 | nw lu ip dns.google. -o yaml 28 | 29 | 30 | ``` 31 | 32 | ### Options 33 | 34 | ``` 35 | -h, --help help for ip 36 | ``` 37 | 38 | ### Options inherited from parent commands 39 | 40 | ``` 41 | -o, --output string Output format. Supported values include json and yaml. 42 | ``` 43 | 44 | ### SEE ALSO 45 | 46 | * [networker lookup](networker_lookup.md) - Lookup hostnames, IPs, ISPs, nameservers, and networks. 47 | 48 | ###### Auto generated by spf13/cobra on 1-Jul-2023 49 | -------------------------------------------------------------------------------- /docs/networker_lookup_isp.md: -------------------------------------------------------------------------------- 1 | ## networker lookup isp 2 | 3 | Lookup the internet service provider of a remote host. 4 | 5 | ``` 6 | networker lookup isp [flags] 7 | ``` 8 | 9 | ### Examples 10 | 11 | ``` 12 | 13 | # Lookup ISP by ip or hostname: 14 | 15 | networker lookup isp 8.8.8.8 16 | networker lookup isp dns.google. 17 | 18 | # Lookup ISP by ip or hostname(short-hand): 19 | 20 | nw lu isp 8.8.8.8 21 | nw lu isp dns.google. 22 | 23 | # Lookup ISP by ip or hostname(short-hand) and output as json: 24 | 25 | nw lu isp 8.8.8.8 -o json 26 | nw lu isp dns.google. -o json 27 | 28 | # Lookup ISP by ip or hostname(short-hand) and output as yaml: 29 | 30 | nw lu isp 8.8.8.8 -o yaml 31 | nw lu isp dns.google. -o yaml 32 | 33 | ``` 34 | 35 | ### Options 36 | 37 | ``` 38 | -h, --help help for isp 39 | ``` 40 | 41 | ### Options inherited from parent commands 42 | 43 | ``` 44 | -o, --output string Output format. Supported values include json and yaml. 45 | ``` 46 | 47 | ### SEE ALSO 48 | 49 | * [networker lookup](networker_lookup.md) - Lookup hostnames, IPs, ISPs, nameservers, and networks. 50 | 51 | ###### Auto generated by spf13/cobra on 1-Jul-2023 52 | -------------------------------------------------------------------------------- /docs/networker_lookup_nameservers.md: -------------------------------------------------------------------------------- 1 | ## networker lookup nameservers 2 | 3 | Lookup nameservers for the provided hostname. 4 | 5 | ``` 6 | networker lookup nameservers [flags] 7 | ``` 8 | 9 | ### Examples 10 | 11 | ``` 12 | 13 | # Lookup nameservers by hostname: 14 | 15 | networker lookup nameservers dns.google. 16 | 17 | # Lookup nameservers by hostname(short-hand): 18 | 19 | nw lu ns dns.google. 20 | 21 | # Lookup nameservers by hostname(short-hand) and output as json: 22 | 23 | nw lu ns dns.google. -o json 24 | 25 | # Lookup nameservers by hostname(short-hand) and output as yaml: 26 | 27 | nw lu ns dns.google. -o yaml 28 | 29 | ``` 30 | 31 | ### Options 32 | 33 | ``` 34 | -h, --help help for nameservers 35 | ``` 36 | 37 | ### Options inherited from parent commands 38 | 39 | ``` 40 | -o, --output string Output format. Supported values include json and yaml. 41 | ``` 42 | 43 | ### SEE ALSO 44 | 45 | * [networker lookup](networker_lookup.md) - Lookup hostnames, IPs, ISPs, nameservers, and networks. 46 | 47 | ###### Auto generated by spf13/cobra on 1-Jul-2023 48 | -------------------------------------------------------------------------------- /docs/networker_lookup_network.md: -------------------------------------------------------------------------------- 1 | ## networker lookup network 2 | 3 | Lookup the network address of a provided host. 4 | 5 | ``` 6 | networker lookup network [flags] 7 | ``` 8 | 9 | ### Examples 10 | 11 | ``` 12 | 13 | # Lookup network by ip or hostname: 14 | 15 | networker lookup network 8.8.8.8 16 | networker lookup network dns.google. 17 | 18 | # Lookup network by ip or hostname(short-hand): 19 | 20 | nw lu n 8.8.8.8 21 | nw lu n dns.google. 22 | 23 | # Lookup network by ip or hostname(short-hand) and output as json: 24 | 25 | nw lu n 8.8.8.8 -o json 26 | nw lu n dns.google. -o json 27 | 28 | # Lookup network by ip or hostname(short-hand) and output as yaml: 29 | 30 | nw lu n 8.8.8.8 -o yaml 31 | nw lu n dns.google. -o yaml 32 | 33 | 34 | ``` 35 | 36 | ### Options 37 | 38 | ``` 39 | -h, --help help for network 40 | ``` 41 | 42 | ### Options inherited from parent commands 43 | 44 | ``` 45 | -o, --output string Output format. Supported values include json and yaml. 46 | ``` 47 | 48 | ### SEE ALSO 49 | 50 | * [networker lookup](networker_lookup.md) - Lookup hostnames, IPs, ISPs, nameservers, and networks. 51 | 52 | ###### Auto generated by spf13/cobra on 1-Jul-2023 53 | -------------------------------------------------------------------------------- /docs/networker_request.md: -------------------------------------------------------------------------------- 1 | ## networker request 2 | 3 | Send an HTTP request. 4 | 5 | ``` 6 | networker request [flags] 7 | ``` 8 | 9 | ### Examples 10 | 11 | ``` 12 | 13 | # POST request using json body sourced from stdin(short-hand): 14 | 15 | nw r \ 16 | -H "Authorization: Bearer doesntmatter" \ 17 | -m post \ 18 | -b '{"field": "doesntmatter"}' \ 19 | https://some-url.com/api/v1/some/endpoint 20 | 21 | # POST request using json body sourced from file: 22 | 23 | nw r \ 24 | -H "Authorization: Bearer doesntmatter" \ 25 | -m post -b /path/to/file.json \ 26 | https://some-url.com/api/v1/some/endpoint 27 | 28 | # PUT request for file upload: 29 | 30 | nw r \ 31 | -H "Authorization: Bearer doesntmatter" \ 32 | -m put \ 33 | -f formname=/path/to/file1.jpeg \ 34 | https://some-url.com/api/v1/some/endpoint 35 | 36 | # PUT request for uploading multiple files: 37 | 38 | nw r \ 39 | -H "Authorization: Bearer doesntmatter" \ 40 | -m put \ 41 | -f formname=/path/to/file1.jpeg,/path/to/file2.jpeg,/path/to/file3.jpeg \ 42 | https://some-url.com/api/v1/some/endpoint 43 | 44 | # GET(default if -m is not provided) request + silence all output except json response body: 45 | 46 | nw r https://jsonplaceholder.typicode.com/todos/1 -s 47 | 48 | # GET(default if -m is not provided) + include all response headers in output: 49 | 50 | nw r https://jsonplaceholder.typicode.com/todos/1 -v 51 | 52 | ``` 53 | 54 | ### Options 55 | 56 | ``` 57 | -b, --body string Request body. (you can use a JSON string literal or a path to a json file) 58 | -f, --files string Upload form file(s). (format: formname=path/to/file1,path/to/file2,path/to/file3) 59 | -H, --headers strings Request headers.(format: key:value,key:value,key:value) 60 | -h, --help help for request 61 | -m, --method string Request method. (default "GET") 62 | -s, --silence Omit output of everything except JSON response body. 63 | -v, --verbose Include response headers in output. 64 | ``` 65 | 66 | ### Options inherited from parent commands 67 | 68 | ``` 69 | -o, --output string Output format. Supported values include json and yaml. 70 | ``` 71 | 72 | ### SEE ALSO 73 | 74 | * [networker](networker.md) - A simple networking utility. 75 | 76 | ###### Auto generated by spf13/cobra on 4-Jun-2022 77 | -------------------------------------------------------------------------------- /docs/networker_scan.md: -------------------------------------------------------------------------------- 1 | ## networker scan 2 | 3 | Scan hosts for open ports. 4 | 5 | ``` 6 | networker scan [flags] 7 | ``` 8 | 9 | ### Examples 10 | 11 | ``` 12 | 13 | # Scan well-known ports(first 1024) of all devices on network: 14 | 15 | networker scan 16 | 17 | # Scan well-known ports(first 1024) of all devices on network(short-hand): 18 | 19 | nw s 20 | 21 | # Scan well-known ports(first 1024) of all devices on network(short-hand) and output as json: 22 | 23 | nw s -o json 24 | 25 | # Scan well-known ports(first 1024) of all devices on network(short-hand) and output as yaml: 26 | 27 | nw s -o yaml 28 | 29 | # Scan all ports of all devices on network: 30 | 31 | networker scan --all-ports 32 | 33 | # Scan all ports of all devices on network(short-hand): 34 | 35 | nw s --all-ports 36 | 37 | # Scan all ports of all devices on network(short-hand) and output as json: 38 | 39 | nw s -o json --all-ports 40 | 41 | # Scan all ports of all devices on network(short-hand) and output as yaml: 42 | 43 | nw s -o yaml --all-ports 44 | 45 | # Scan well-known ports(first 1024) of single host: 46 | 47 | networker scan localhost 48 | 49 | # Scan well-known ports(first 1024) of single host(short-hand): 50 | 51 | nw s localhost 52 | 53 | # Scan well-known ports(first 1024) of single host(short-hand) and output as json: 54 | 55 | nw s localhost -o json 56 | 57 | # Scan well-known ports(first 1024) of single host(short-hand) and output as yaml: 58 | 59 | nw s localhost -o yaml 60 | 61 | # Scan all ports of single host: 62 | 63 | networker scan localhost --all-ports 64 | 65 | # Scan all ports of single host(short-hand): 66 | 67 | nw s localhost --all-ports 68 | 69 | # Scan all ports of single host(short-hand) and output as json: 70 | 71 | nw s localhost -o json --all-ports 72 | 73 | # Scan all ports of single host(short-hand) and output as yaml: 74 | 75 | nw s localhost -o yaml --all-ports 76 | 77 | 78 | ``` 79 | 80 | ### Options 81 | 82 | ``` 83 | --all-ports Scan all ports(scans first 1024 if not enabled). 84 | -h, --help help for scan 85 | ``` 86 | 87 | ### Options inherited from parent commands 88 | 89 | ``` 90 | -o, --output string Output format. Supported values include json and yaml. 91 | ``` 92 | 93 | ### SEE ALSO 94 | 95 | * [networker](networker.md) - A simple networking utility. 96 | 97 | ###### Auto generated by spf13/cobra on 1-Jul-2023 98 | -------------------------------------------------------------------------------- /docs/networker_shell.md: -------------------------------------------------------------------------------- 1 | ## networker shell 2 | 3 | Serve and establish connections with remote shells. 4 | 5 | ``` 6 | networker shell [flags] 7 | ``` 8 | 9 | ### Examples 10 | 11 | ``` 12 | 13 | # Serve using the defaults(bash is the default shell and 4444 is the default port): 14 | 15 | nw shell serve 16 | 17 | # Serve a particular shell on a particular port: 18 | 19 | nw shell serve zsh --port 9000 20 | 21 | # Establish a new shell session by dialing a networker initiated shell server. 22 | 23 | nw shell dial some.remote.ip.addr:9000 24 | 25 | 26 | ``` 27 | 28 | ### Options 29 | 30 | ``` 31 | -h, --help help for shell 32 | ``` 33 | 34 | ### Options inherited from parent commands 35 | 36 | ``` 37 | -o, --output string Output format. Supported values include json and yaml. 38 | ``` 39 | 40 | ### SEE ALSO 41 | 42 | * [networker](networker.md) - A simple networking utility. 43 | * [networker shell dial](networker_shell_dial.md) - Dial a shell server. 44 | * [networker shell serve](networker_shell_serve.md) - Start a shell server. 45 | 46 | ###### Auto generated by spf13/cobra on 1-Jul-2023 47 | -------------------------------------------------------------------------------- /docs/networker_shell_dial.md: -------------------------------------------------------------------------------- 1 | ## networker shell dial 2 | 3 | Dial a shell server. 4 | 5 | ``` 6 | networker shell dial [flags] 7 | ``` 8 | 9 | ### Examples 10 | 11 | ``` 12 | 13 | # Establish a new shell session by dialing a networker initiated shell server. 14 | 15 | nw shell dial some.remote.ip.addr:9000 16 | 17 | 18 | ``` 19 | 20 | ### Options 21 | 22 | ``` 23 | -h, --help help for dial 24 | ``` 25 | 26 | ### Options inherited from parent commands 27 | 28 | ``` 29 | -o, --output string Output format. Supported values include json and yaml. 30 | ``` 31 | 32 | ### SEE ALSO 33 | 34 | * [networker shell](networker_shell.md) - Serve and establish connections with remote shells. 35 | 36 | ###### Auto generated by spf13/cobra on 1-Jul-2023 37 | -------------------------------------------------------------------------------- /docs/networker_shell_serve.md: -------------------------------------------------------------------------------- 1 | ## networker shell serve 2 | 3 | Start a shell server. 4 | 5 | ``` 6 | networker shell serve [flags] 7 | ``` 8 | 9 | ### Examples 10 | 11 | ``` 12 | 13 | # Serve using the defaults(bash is the default shell and 4444 is the default port): 14 | 15 | nw shell serve 16 | 17 | # Serve a particular shell on a particular port: 18 | 19 | nw shell serve zsh -p 9000 20 | 21 | 22 | ``` 23 | 24 | ### Options 25 | 26 | ``` 27 | -h, --help help for serve 28 | -p, --port int Port to serve shell on. (default 4444) 29 | ``` 30 | 31 | ### Options inherited from parent commands 32 | 33 | ``` 34 | -o, --output string Output format. Supported values include json and yaml. 35 | ``` 36 | 37 | ### SEE ALSO 38 | 39 | * [networker shell](networker_shell.md) - Serve and establish connections with remote shells. 40 | 41 | ###### Auto generated by spf13/cobra on 1-Jul-2023 42 | -------------------------------------------------------------------------------- /go.mod: -------------------------------------------------------------------------------- 1 | module github.com/fuskovic/networker/v3 2 | 3 | go 1.21 4 | 5 | toolchain go1.22.0 6 | 7 | require ( 8 | cdr.dev/coder-cli v1.17.0 9 | github.com/ammario/ipisp v1.0.0 10 | github.com/jackpal/gateway v1.0.15 11 | github.com/spf13/cobra v1.4.0 12 | github.com/stretchr/testify v1.9.0 13 | ) 14 | 15 | require ( 16 | github.com/fatih/color v1.10.0 // indirect 17 | github.com/mattn/go-colorable v0.1.8 // indirect 18 | github.com/mattn/go-isatty v0.0.12 // indirect 19 | github.com/stretchr/objx v0.5.2 // indirect 20 | golang.org/x/net v0.25.0 // indirect 21 | golang.org/x/sys v0.28.0 // indirect 22 | golang.org/x/term v0.27.0 // indirect 23 | ) 24 | 25 | require ( 26 | github.com/briandowns/spinner v1.18.1 27 | github.com/cpuguy83/go-md2man/v2 v2.0.1 // indirect 28 | github.com/creack/pty v1.1.18 29 | github.com/davecgh/go-spew v1.1.1 // indirect 30 | github.com/inconshreveable/mousetrap v1.0.0 // indirect 31 | github.com/pkg/errors v0.8.1 // indirect 32 | github.com/pmezard/go-difflib v1.0.0 // indirect 33 | github.com/russross/blackfriday/v2 v2.1.0 // indirect 34 | github.com/spf13/pflag v1.0.5 // indirect 35 | github.com/tatsushid/go-fastping v0.0.0-20160109021039-d7bb493dee3e 36 | golang.org/x/crypto v0.31.0 37 | gopkg.in/yaml.v2 v2.4.0 // indirect 38 | gopkg.in/yaml.v3 v3.0.1 39 | ) 40 | -------------------------------------------------------------------------------- /go.sum: -------------------------------------------------------------------------------- 1 | cdr.dev/coder-cli v1.17.0 h1:mmDksrdTVyASQSnB7h0yI4+IBp728OOlYZx3sMmSNdM= 2 | cdr.dev/coder-cli v1.17.0/go.mod h1:qx4lPbKKSbXOYQMP6KeRkhrmh2RO3QAZmS7fginCoA0= 3 | cdr.dev/slog v1.3.0/go.mod h1:C5OL99WyuOK8YHZdYY57dAPN1jK2WJlCdq2VP6xeQns= 4 | cdr.dev/slog v1.4.0 h1:tLXQJ/hZ5Q051h0MBHSd2Ha8xzdXj7CjtzmG/8dUvUk= 5 | cdr.dev/slog v1.4.0/go.mod h1:C5OL99WyuOK8YHZdYY57dAPN1jK2WJlCdq2VP6xeQns= 6 | cdr.dev/wsep v0.0.0-20200728013649-82316a09813f/go.mod h1:2VKClUml3gfmLez0gBxTJIjSKszpQotc2ZqPdApfK/Y= 7 | cloud.google.com/go v0.26.0/go.mod h1:aQUYkXzVsufM+DwF1aE+0xfcU+56JwCaLick0ClmMTw= 8 | cloud.google.com/go v0.34.0/go.mod h1:aQUYkXzVsufM+DwF1aE+0xfcU+56JwCaLick0ClmMTw= 9 | cloud.google.com/go v0.38.0/go.mod h1:990N+gfupTy94rShfmMCWGDn0LpTmnzTp2qbd1dvSRU= 10 | cloud.google.com/go v0.44.1/go.mod h1:iSa0KzasP4Uvy3f1mN/7PiObzGgflwredwwASm/v6AU= 11 | cloud.google.com/go v0.44.2/go.mod h1:60680Gw3Yr4ikxnPRS/oxxkBccT6SA1yMk63TGekxKY= 12 | cloud.google.com/go v0.45.1/go.mod h1:RpBamKRgapWJb87xiFSdk4g1CME7QZg3uwTez+TSTjc= 13 | cloud.google.com/go v0.46.3/go.mod h1:a6bKKbmY7er1mI7TEI4lsAkts/mkhTSZK8w33B4RAg0= 14 | cloud.google.com/go v0.49.0/go.mod h1:hGvAdzcWNbyuxS3nWhD7H2cIJxjRRTRLQVB0bdputVY= 15 | cloud.google.com/go/bigquery v1.0.1/go.mod h1:i/xbL2UlR5RvWAURpBYZTtm/cXjCha9lbfbpx4poX+o= 16 | cloud.google.com/go/datastore v1.0.0/go.mod h1:LXYbyblFSglQ5pkeyhO+Qmw7ukd3C+pD7TKLgZqpHYE= 17 | cloud.google.com/go/firestore v1.1.0/go.mod h1:ulACoGHTpvq5r8rxGJ4ddJZBZqakUQqClKRT5SZwBmk= 18 | cloud.google.com/go/pubsub v1.0.1/go.mod h1:R0Gpsv3s54REJCy4fxDixWD93lHJMoZTyQ2kNxGRt3I= 19 | cloud.google.com/go/storage v1.0.0/go.mod h1:IhtSnM/ZTZV8YYJWCY8RULGVqBDmpoyjwiyrjsg+URw= 20 | dmitri.shuralyov.com/gpu/mtl v0.0.0-20190408044501-666a987793e9/go.mod h1:H6x//7gZCb22OMCxBHrMx7a5I7Hp++hsVxbQ4BYO7hU= 21 | github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU= 22 | github.com/BurntSushi/xgb v0.0.0-20160522181843-27f122750802/go.mod h1:IVnqGOEym/WlBOVXweHU+Q+/VP0lqqI8lqeDx9IjBqo= 23 | github.com/GeertJohan/go.incremental v1.0.0/go.mod h1:6fAjUhbVuX1KcMD3c8TEgVUqmo4seqhv0i0kdATSkM0= 24 | github.com/GeertJohan/go.rice v1.0.0/go.mod h1:eH6gbSOAUv07dQuZVnBmoDP8mgsM1rtixis4Tib9if0= 25 | github.com/OneOfOne/xxhash v1.2.2/go.mod h1:HSdplMjZKSmBqAxg5vPj2TmRDmfkzw+cTzAElWljhcU= 26 | github.com/akavel/rsrc v0.8.0/go.mod h1:uLoCtb9J+EyAqh+26kdrTgmzRBFPGOolLWKpdxkKq+c= 27 | github.com/alecthomas/assert v0.0.0-20170929043011-405dbfeb8e38/go.mod h1:r7bzyVFMNntcxPZXK3/+KdruV1H5KSlyVY0gc+NgInI= 28 | github.com/alecthomas/chroma v0.7.0 h1:z+0HgTUmkpRDRz0SRSdMaqOLfJV4F+N1FPDZUZIDUzw= 29 | github.com/alecthomas/chroma v0.7.0/go.mod h1:1U/PfCsTALWWYHDnsIQkxEBM0+6LLe0v8+RSVMOwxeY= 30 | github.com/alecthomas/colour v0.0.0-20160524082231-60882d9e2721/go.mod h1:QO9JBoKquHd+jz9nshCh40fOfO+JzsoXy8qTHF68zU0= 31 | github.com/alecthomas/kong v0.1.17-0.20190424132513-439c674f7ae0/go.mod h1:+inYUSluD+p4L8KdviBSgzcqEjUQOfC5fQDRFuc36lI= 32 | github.com/alecthomas/kong v0.2.1-0.20190708041108-0548c6b1afae/go.mod h1:+inYUSluD+p4L8KdviBSgzcqEjUQOfC5fQDRFuc36lI= 33 | github.com/alecthomas/kong-hcl v0.1.8-0.20190615233001-b21fea9723c8/go.mod h1:MRgZdU3vrFd05IQ89AxUZ0aYdF39BYoNFa324SodPCA= 34 | github.com/alecthomas/repr v0.0.0-20180818092828-117648cd9897/go.mod h1:xTS7Pm1pD1mvyM075QCDSRqH6qRLXylzS24ZTpRiSzQ= 35 | github.com/alecthomas/template v0.0.0-20160405071501-a0175ee3bccc/go.mod h1:LOuyumcjzFXgccqObfd/Ljyb9UuFJ6TxHnclSeseNhc= 36 | github.com/alecthomas/units v0.0.0-20151022065526-2efee857e7cf/go.mod h1:ybxpYRFXyAe+OPACYpWeL0wqObRcbAqCMya13uyzqw0= 37 | github.com/ammario/ipisp v1.0.0 h1:U4xdVMBFWm0/4sHrQ3hVMC+ygg/Ynm4/vdFdkVAex1o= 38 | github.com/ammario/ipisp v1.0.0/go.mod h1:HM60VFpmEWyU+FisnTTHCeswaU3RW0dCVHihgIGUEGM= 39 | github.com/armon/circbuf v0.0.0-20150827004946-bbbad097214e/go.mod h1:3U/XgcO3hCbHZ8TKRvWD2dDTCfh9M9ya+I9JpbB7O8o= 40 | github.com/armon/go-metrics v0.0.0-20180917152333-f0300d1749da/go.mod h1:Q73ZrmVTwzkszR9V5SSuryQ31EELlFMUz1kKyl939pY= 41 | github.com/armon/go-radix v0.0.0-20180808171621-7fddfc383310/go.mod h1:ufUuZ+zHj4x4TnLV4JWEpy2hxWSpsRywHrMgIH9cCH8= 42 | github.com/beorn7/perks v0.0.0-20180321164747-3a771d992973/go.mod h1:Dwedo/Wpr24TaqPxmxbtue+5NUziq4I4S80YR8gNf3Q= 43 | github.com/beorn7/perks v1.0.0/go.mod h1:KWe93zE9D1o94FZ5RNwFwVgaQK1VOXiVxmqh+CedLV8= 44 | github.com/bgentry/speakeasy v0.1.0/go.mod h1:+zsyZBPWlz7T6j88CTgSN5bM796AkVf0kBD4zp0CCIs= 45 | github.com/bketelsen/crypt v0.0.3-0.20200106085610-5cbc8cc4026c/go.mod h1:MKsuJmJgSg28kpZDP6UIiPt0e0Oz0kqKNGyRaWEPv84= 46 | github.com/briandowns/spinner v1.11.1/go.mod h1:QOuQk7x+EaDASo80FEXwlwiA+j/PPIcX3FScO+3/ZPQ= 47 | github.com/briandowns/spinner v1.18.1 h1:yhQmQtM1zsqFsouh09Bk/jCjd50pC3EOGsh28gLVvwY= 48 | github.com/briandowns/spinner v1.18.1/go.mod h1:mQak9GHqbspjC/5iUx3qMlIho8xBS/ppAL/hX5SmPJU= 49 | github.com/census-instrumentation/opencensus-proto v0.2.1/go.mod h1:f6KPmirojxKA12rnyqOA5BBL4O983OfeGPqjHWSTneU= 50 | github.com/cespare/xxhash v1.1.0/go.mod h1:XrSqR1VqqWfGrhpAt58auRo0WTKS1nRRg3ghfAqPWnc= 51 | github.com/chzyer/logex v1.1.10/go.mod h1:+Ywpsq7O8HXn0nuIou7OrIPyXbp3wmkHB+jjWRnGsAI= 52 | github.com/chzyer/readline v0.0.0-20180603132655-2972be24d48e/go.mod h1:nSuG5e5PlCu98SY8svDHJxuZscDgtXS6KTTbou5AhLI= 53 | github.com/chzyer/test v0.0.0-20180213035817-a1ea475d72b1/go.mod h1:Q3SI9o4m/ZMnBNeIyt5eFwwo7qiLfzFZmjNmxjkiQlU= 54 | github.com/client9/misspell v0.3.4/go.mod h1:qj6jICC3Q7zFZvVWo7KLAzC3yx5G7kyvSDkc90ppPyw= 55 | github.com/coreos/bbolt v1.3.2/go.mod h1:iRUV2dpdMOn7Bo10OQBFzIJO9kkE559Wcmn+qkEiiKk= 56 | github.com/coreos/etcd v3.3.13+incompatible/go.mod h1:uF7uidLiAD3TWHmW31ZFd/JWoc32PjwdhPthX9715RE= 57 | github.com/coreos/go-semver v0.3.0/go.mod h1:nnelYz7RCh+5ahJtPPxZlU+153eP4D4r3EedlOD2RNk= 58 | github.com/coreos/go-systemd v0.0.0-20190321100706-95778dfbb74e/go.mod h1:F5haX7vjVVG0kc13fIWeqUViNPyEJxv/OmvnBo0Yme4= 59 | github.com/coreos/pkg v0.0.0-20180928190104-399ea9e2e55f/go.mod h1:E3G3o1h8I7cfcXa63jLwjI0eiQQMgzzUDFVpN/nH/eA= 60 | github.com/cpuguy83/go-md2man/v2 v2.0.0/go.mod h1:maD7wRr/U5Z6m/iR4s+kqSMx2CaBsrgA7czyZG/E6dU= 61 | github.com/cpuguy83/go-md2man/v2 v2.0.1 h1:r/myEWzV9lfsM1tFLgDyu0atFtJ1fXn261LKYj/3DxU= 62 | github.com/cpuguy83/go-md2man/v2 v2.0.1/go.mod h1:tgQtvFlXSQOSOSIRvRPT7W67SCa46tRHOmNcaadrF8o= 63 | github.com/creack/pty v1.1.11/go.mod h1:oKZEueFk5CKHvIhNR5MUki03XCEU+Q6VDXinZuGJ33E= 64 | github.com/creack/pty v1.1.18 h1:n56/Zwd5o6whRC5PMGretI4IdRLlmBXYNjScPaBgsbY= 65 | github.com/creack/pty v1.1.18/go.mod h1:MOBLtS5ELjhRRrroQr9kyvTxUAFNvYEK993ew/Vr4O4= 66 | github.com/daaku/go.zipexe v1.0.0/go.mod h1:z8IiR6TsVLEYKwXAoE/I+8ys/sDkgTzSL0CLnGVd57E= 67 | github.com/danwakefield/fnmatch v0.0.0-20160403171240-cbb64ac3d964 h1:y5HC9v93H5EPKqaS1UYVg1uYah5Xf51mBfIoWehClUQ= 68 | github.com/danwakefield/fnmatch v0.0.0-20160403171240-cbb64ac3d964/go.mod h1:Xd9hchkHSWYkEqJwUGisez3G1QY8Ryz0sdWrLPMGjLk= 69 | github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= 70 | github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= 71 | github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= 72 | github.com/dgrijalva/jwt-go v3.2.0+incompatible/go.mod h1:E3ru+11k8xSBh+hMPgOLZmtrrCbhqsmaPHjLKYnJCaQ= 73 | github.com/dgryski/go-sip13 v0.0.0-20181026042036-e10d5fee7954/go.mod h1:vAd38F8PWV+bWy6jNmig1y/TA+kYO4g3RSRF0IAv0no= 74 | github.com/dlclark/regexp2 v1.1.6/go.mod h1:2pZnwuY/m+8K6iRw6wQdMtk+rH5tNGR1i55kozfMjCc= 75 | github.com/dlclark/regexp2 v1.2.0 h1:8sAhBGEM0dRWogWqWyQeIJnxjWO6oIjl8FKqREDsGfk= 76 | github.com/dlclark/regexp2 v1.2.0/go.mod h1:2pZnwuY/m+8K6iRw6wQdMtk+rH5tNGR1i55kozfMjCc= 77 | github.com/envoyproxy/go-control-plane v0.9.0/go.mod h1:YTl/9mNaCwkRvm6d1a2C3ymFceY/DCBVvsKhRF0iEA4= 78 | github.com/envoyproxy/protoc-gen-validate v0.1.0/go.mod h1:iSmxcyjqTsJpI2R4NaDN7+kN2VEUnK/pcBlmesArF7c= 79 | github.com/fatih/color v1.7.0/go.mod h1:Zm6kSWBoL9eyXnKyktHP6abPY2pDugNf5KwzbycvMj4= 80 | github.com/fatih/color v1.10.0 h1:s36xzo75JdqLaaWoiEHk767eHiwo0598uUxyfiPkDsg= 81 | github.com/fatih/color v1.10.0/go.mod h1:ELkj/draVOlAH/xkhN6mQ50Qd0MPOk5AAr3maGEBuJM= 82 | github.com/fsnotify/fsnotify v1.4.7/go.mod h1:jwhsz4b93w/PPRr/qN1Yymfu8t87LnFCMoQvtojpjFo= 83 | github.com/ghodss/yaml v1.0.0/go.mod h1:4dBDuWmgqj2HViK6kFavaiC9ZROes6MMH2rRYeMEF04= 84 | github.com/gin-contrib/sse v0.1.0/go.mod h1:RHrZQHXnP2xjPF+u1gW/2HnVO7nvIa9PG3Gm+fLHvGI= 85 | github.com/gin-gonic/gin v1.6.3/go.mod h1:75u5sXoLsGZoRN5Sgbi1eraJ4GU3++wFwWzhwvtwp4M= 86 | github.com/go-gl/glfw v0.0.0-20190409004039-e6da0acd62b1/go.mod h1:vR7hzQXu2zJy9AVAgeJqvqgH9Q5CA+iKCZ2gyEVpxRU= 87 | github.com/go-kit/kit v0.8.0/go.mod h1:xBxKIO96dXMWWy0MnWVtmwkA9/13aqxPnvrjFYMA2as= 88 | github.com/go-logfmt/logfmt v0.3.0/go.mod h1:Qt1PoO58o5twSAckw1HlFXLmHsOX5/0LbT9GBnD5lWE= 89 | github.com/go-logfmt/logfmt v0.4.0/go.mod h1:3RMwSq7FuexP4Kalkev3ejPJsZTpXXBr9+V4qmtdjCk= 90 | github.com/go-playground/assert/v2 v2.0.1/go.mod h1:VDjEfimB/XKnb+ZQfWdccd7VUvScMdVu0Titje2rxJ4= 91 | github.com/go-playground/locales v0.13.0/go.mod h1:taPMhCMXrRLJO55olJkUXHZBHCxTMfnGwq/HNwmWNS8= 92 | github.com/go-playground/universal-translator v0.17.0/go.mod h1:UkSxE5sNxxRwHyU+Scu5vgOQjsIJAF8j9muTVoKLVtA= 93 | github.com/go-playground/validator/v10 v10.2.0/go.mod h1:uOYAAleCW8F/7oMFd6aG0GOhaH6EGOAJShg8Id5JGkI= 94 | github.com/go-stack/stack v1.8.0/go.mod h1:v0f6uXyyMGvRgIKkXu+yp6POWl0qKG85gN/melR3HDY= 95 | github.com/gobwas/httphead v0.0.0-20180130184737-2c6c146eadee/go.mod h1:L0fX3K22YWvt/FAX9NnzrNzcI4wNYi9Yku4O0LKYflo= 96 | github.com/gobwas/pool v0.2.0/go.mod h1:q8bcK0KcYlCgd9e7WYLm9LpyS+YeLd8JVDW6WezmKEw= 97 | github.com/gobwas/ws v1.0.2/go.mod h1:szmBTxLgaFppYjEmNtny/v3w89xOydFnnZMcgRRu/EM= 98 | github.com/gogo/protobuf v1.1.1/go.mod h1:r8qH/GZQm5c6nD/R0oafs1akxWv10x8SbQlK7atdtwQ= 99 | github.com/gogo/protobuf v1.2.1/go.mod h1:hp+jE20tsWTFYpLwKvXlhS1hjn+gTNwPg2I6zVXpSg4= 100 | github.com/golang/glog v0.0.0-20160126235308-23def4e6c14b/go.mod h1:SBH7ygxi8pfUlaOkMMuAQtPIUF8ecWP5IEl/CR7VP2Q= 101 | github.com/golang/groupcache v0.0.0-20190129154638-5b532d6fd5ef/go.mod h1:cIg4eruTrX1D+g88fzRXU5OdNfaM+9IcxsU14FzY7Hc= 102 | github.com/golang/groupcache v0.0.0-20190702054246-869f871628b6/go.mod h1:cIg4eruTrX1D+g88fzRXU5OdNfaM+9IcxsU14FzY7Hc= 103 | github.com/golang/groupcache v0.0.0-20191027212112-611e8accdfc9 h1:uHTyIjqVhYRhLbJ8nIiOJHkEZZ+5YoOsAbD3sk82NiE= 104 | github.com/golang/groupcache v0.0.0-20191027212112-611e8accdfc9/go.mod h1:cIg4eruTrX1D+g88fzRXU5OdNfaM+9IcxsU14FzY7Hc= 105 | github.com/golang/mock v1.1.1/go.mod h1:oTYuIxOrZwtPieC+H1uAHpcLFnEyAGVDL/k47Jfbm0A= 106 | github.com/golang/mock v1.2.0/go.mod h1:oTYuIxOrZwtPieC+H1uAHpcLFnEyAGVDL/k47Jfbm0A= 107 | github.com/golang/mock v1.3.1/go.mod h1:sBzyDLLjw3U8JLTeZvSv8jJB+tU5PVekmnlKIyFUx0Y= 108 | github.com/golang/protobuf v1.2.0/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U= 109 | github.com/golang/protobuf v1.3.1/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U= 110 | github.com/golang/protobuf v1.3.2/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U= 111 | github.com/golang/protobuf v1.3.3/go.mod h1:vzj43D7+SQXF/4pzW/hwtAqwc6iTitCiVSaWz5lYuqw= 112 | github.com/golang/protobuf v1.3.5/go.mod h1:6O5/vntMXwX2lRkT1hjjk0nAC1IDOTvTlVgjlRvqsdk= 113 | github.com/google/btree v0.0.0-20180813153112-4030bb1f1f0c/go.mod h1:lNA+9X1NB3Zf8V7Ke586lFgjr2dZNuvo3lPJSGZ5JPQ= 114 | github.com/google/btree v1.0.0/go.mod h1:lNA+9X1NB3Zf8V7Ke586lFgjr2dZNuvo3lPJSGZ5JPQ= 115 | github.com/google/go-cmp v0.2.0/go.mod h1:oXzfMopK8JAjlY9xF4vHSVASa0yLyX7SntLO5aqRK0M= 116 | github.com/google/go-cmp v0.3.0/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMywk6iLU= 117 | github.com/google/go-cmp v0.3.2-0.20191216170541-340f1ebe299e/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= 118 | github.com/google/go-cmp v0.4.0/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= 119 | github.com/google/go-cmp v0.5.5 h1:Khx7svrCpmxxtHBq5j2mp/xVjsi8hQMfNLvJFAlrGgU= 120 | github.com/google/go-cmp v0.5.5/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= 121 | github.com/google/gofuzz v1.0.0/go.mod h1:dBl0BpW6vV/+mYPU4Po3pmUjxk6FQPldtuIdl/M65Eg= 122 | github.com/google/martian v2.1.0+incompatible/go.mod h1:9I4somxYTbIHy5NJKHRl3wXiIaQGbYVAs8BPL6v8lEs= 123 | github.com/google/pprof v0.0.0-20181206194817-3ea8567a2e57/go.mod h1:zfwlbNMJ+OItoe0UupaVj+oy1omPYYDuagoSzA8v9mc= 124 | github.com/google/pprof v0.0.0-20190515194954-54271f7e092f/go.mod h1:zfwlbNMJ+OItoe0UupaVj+oy1omPYYDuagoSzA8v9mc= 125 | github.com/google/renameio v0.1.0/go.mod h1:KWCgfxg9yswjAJkECMjeO8J8rahYeXnNhOm40UhjYkI= 126 | github.com/googleapis/gax-go/v2 v2.0.4/go.mod h1:0Wqv26UfaUD9n4G6kQubkQ+KchISgw+vpHVxEJEs9eg= 127 | github.com/googleapis/gax-go/v2 v2.0.5/go.mod h1:DWXyrwAJ9X0FpwwEdw+IPEYBICEFu5mhpdKc/us6bOk= 128 | github.com/gopherjs/gopherjs v0.0.0-20181017120253-0766667cb4d1/go.mod h1:wJfORRmW1u3UXTncJ5qlYoELFm8eSnnEO6hX4iZ3EWY= 129 | github.com/gorilla/csrf v1.6.0/go.mod h1:7tSf8kmjNYr7IWDCYhd3U8Ck34iQ/Yw5CJu7bAkHEGI= 130 | github.com/gorilla/handlers v1.4.1/go.mod h1:Qkdc/uu4tH4g6mTK6auzZ766c4CA0Ng8+o/OAirnOIQ= 131 | github.com/gorilla/mux v1.7.3/go.mod h1:1lud6UwP+6orDFRuTfBEV8e9/aOM/c4fVVCaMa2zaAs= 132 | github.com/gorilla/securecookie v1.1.1/go.mod h1:ra0sb63/xPlUeL+yeDciTfxMRAA+MP+HVt/4epWDjd4= 133 | github.com/gorilla/websocket v1.4.1/go.mod h1:YR8l580nyteQvAITg2hZ9XVh4b55+EU/adAjf1fMHhE= 134 | github.com/gorilla/websocket v1.4.2/go.mod h1:YR8l580nyteQvAITg2hZ9XVh4b55+EU/adAjf1fMHhE= 135 | github.com/grpc-ecosystem/go-grpc-middleware v1.0.0/go.mod h1:FiyG127CGDf3tlThmgyCl78X/SZQqEOJBCDaAfeWzPs= 136 | github.com/grpc-ecosystem/go-grpc-prometheus v1.2.0/go.mod h1:8NvIoxWQoOIhqOTXgfV/d3M/q6VIi02HzZEHgUlZvzk= 137 | github.com/grpc-ecosystem/grpc-gateway v1.9.0/go.mod h1:vNeuVxBJEsws4ogUvrchl83t/GYV9WGTSLVdBhOQFDY= 138 | github.com/hashicorp/consul/api v1.1.0/go.mod h1:VmuI/Lkw1nC05EYQWNKwWGbkg+FbDBtguAZLlVdkD9Q= 139 | github.com/hashicorp/consul/sdk v0.1.1/go.mod h1:VKf9jXwCTEY1QZP2MOLRhb5i/I/ssyNV1vwHyQBF0x8= 140 | github.com/hashicorp/errwrap v1.0.0/go.mod h1:YH+1FKiLXxHSkmPseP+kNlulaMuP3n2brvKWEqk/Jc4= 141 | github.com/hashicorp/go-cleanhttp v0.5.1/go.mod h1:JpRdi6/HCYpAwUzNwuwqhbovhLtngrth3wmdIIUrZ80= 142 | github.com/hashicorp/go-immutable-radix v1.0.0/go.mod h1:0y9vanUI8NX6FsYoO3zeMjhV/C5i9g4Q3DwcSNZ4P60= 143 | github.com/hashicorp/go-msgpack v0.5.3/go.mod h1:ahLV/dePpqEmjfWmKiqvPkv/twdG7iPBM1vqhUKIvfM= 144 | github.com/hashicorp/go-multierror v1.0.0/go.mod h1:dHtQlpGsu+cZNNAkkCN/P3hoUDHhCYQXV3UM06sGGrk= 145 | github.com/hashicorp/go-rootcerts v1.0.0/go.mod h1:K6zTfqpRlCUIjkwsN4Z+hiSfzSTQa6eBIzfwKfwNnHU= 146 | github.com/hashicorp/go-sockaddr v1.0.0/go.mod h1:7Xibr9yA9JjQq1JpNB2Vw7kxv8xerXegt+ozgdvDeDU= 147 | github.com/hashicorp/go-syslog v1.0.0/go.mod h1:qPfqrKkXGihmCqbJM2mZgkZGvKG1dFdvsLplgctolz4= 148 | github.com/hashicorp/go-uuid v1.0.0/go.mod h1:6SBZvOh/SIDV7/2o3Jml5SYk/TvGqwFJ/bN7x4byOro= 149 | github.com/hashicorp/go-uuid v1.0.1/go.mod h1:6SBZvOh/SIDV7/2o3Jml5SYk/TvGqwFJ/bN7x4byOro= 150 | github.com/hashicorp/go.net v0.0.1/go.mod h1:hjKkEWcCURg++eb33jQU7oqQcI9XDCnUzHA0oac0k90= 151 | github.com/hashicorp/golang-lru v0.5.0/go.mod h1:/m3WP610KZHVQ1SGc6re/UDhFvYD7pJ4Ao+sR/qLZy8= 152 | github.com/hashicorp/golang-lru v0.5.1/go.mod h1:/m3WP610KZHVQ1SGc6re/UDhFvYD7pJ4Ao+sR/qLZy8= 153 | github.com/hashicorp/hcl v1.0.0/go.mod h1:E5yfLk+7swimpb2L/Alb/PJmXilQ/rhwaUYs4T20WEQ= 154 | github.com/hashicorp/logutils v1.0.0/go.mod h1:QIAnNjmIWmVIIkWDTG1z5v++HQmx9WQRO+LraFDTW64= 155 | github.com/hashicorp/mdns v1.0.0/go.mod h1:tL+uN++7HEJ6SQLQ2/p+z2pH24WQKWjBPkE0mNTz8vQ= 156 | github.com/hashicorp/memberlist v0.1.3/go.mod h1:ajVTdAv/9Im8oMAAj5G31PhhMCZJV2pPBoIllUwCN7I= 157 | github.com/hashicorp/serf v0.8.2/go.mod h1:6hOLApaqBFA1NXqRQAsxw9QxuDEvNxSQRwA/JwenrHc= 158 | github.com/inconshreveable/mousetrap v1.0.0 h1:Z8tu5sraLXCXIcARxBp/8cbvlwVa7Z1NHg9XEKhtSvM= 159 | github.com/inconshreveable/mousetrap v1.0.0/go.mod h1:PxqpIevigyE2G7u3NXJIT2ANytuPF1OarO4DADm73n8= 160 | github.com/jackpal/gateway v1.0.15 h1:yb4Gltgr8ApHWWnSyybnDL1vURbqw7ooo7IIL5VZSeg= 161 | github.com/jackpal/gateway v1.0.15/go.mod h1:dbyEDcDhHUh9EmjB9ung81elMUZfG0SoNc2TfTbcj4c= 162 | github.com/jessevdk/go-flags v1.4.0/go.mod h1:4FA24M0QyGHXBuZZK/XkWh8h0e1EYbRYJSGM75WSRxI= 163 | github.com/jonboulle/clockwork v0.1.0/go.mod h1:Ii8DK3G1RaLaWxj9trq07+26W01tbo22gdxWY5EU2bo= 164 | github.com/json-iterator/go v1.1.6/go.mod h1:+SdeFBvtyEkXs7REEP0seUULqWtbJapLOCVDaaPEHmU= 165 | github.com/json-iterator/go v1.1.9/go.mod h1:KdQUCv79m/52Kvf8AW2vK1V8akMuk1QjK/uOdHXbAo4= 166 | github.com/jstemmer/go-junit-report v0.0.0-20190106144839-af01ea7f8024/go.mod h1:6v2b51hI/fHJwM22ozAgKL4VKDeJcHhJFhtBdhmNjmU= 167 | github.com/jtolds/gls v4.20.0+incompatible/go.mod h1:QJZ7F/aHp+rZTRtaJ1ow/lLfFfVYBRgL+9YlvaHOwJU= 168 | github.com/juju/ansiterm v0.0.0-20180109212912-720a0952cc2a/go.mod h1:UJSiEoRfvx3hP73CvoARgeLjaIOjybY9vj8PUPPFGeU= 169 | github.com/julienschmidt/httprouter v1.2.0/go.mod h1:SYymIcj16QtmaHHD7aYtjjsJG7VTCxuUUipMqKk8s4w= 170 | github.com/kirsle/configdir v0.0.0-20170128060238-e45d2f54772f/go.mod h1:4rEELDSfUAlBSyUjPG0JnaNGjf13JySHFeRdD/3dLP0= 171 | github.com/kisielk/errcheck v1.1.0/go.mod h1:EZBBE59ingxPouuu3KfxchcWSUPOHkagtvWXihfKN4Q= 172 | github.com/kisielk/gotool v1.0.0/go.mod h1:XhKaO+MFFWcvkIS/tQcRk01m1F5IRFswLeQ+oQHNcck= 173 | github.com/klauspost/compress v1.10.3/go.mod h1:aoV0uJVorq1K+umq18yTdKaF57EivdYsUV+/s2qKfXs= 174 | github.com/klauspost/compress v1.10.8/go.mod h1:aoV0uJVorq1K+umq18yTdKaF57EivdYsUV+/s2qKfXs= 175 | github.com/konsorten/go-windows-terminal-sequences v1.0.1/go.mod h1:T0+1ngSBFLxvqU3pZ+m/2kptfBszLMUkC4ZK/EgS/cQ= 176 | github.com/kr/logfmt v0.0.0-20140226030751-b84e30acd515/go.mod h1:+0opPa2QZZtGFBFZlji/RkVcI2GknAs/DXo4wKdlNEc= 177 | github.com/kr/pretty v0.1.0 h1:L/CwN0zerZDmRFUapSPitk6f+Q3+0za1rQkzVuMiMFI= 178 | github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo= 179 | github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ= 180 | github.com/kr/text v0.1.0 h1:45sCR5RtlFHMR4UwH9sdQ5TC8v0qDQCHnXt+kaKSTVE= 181 | github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI= 182 | github.com/leodido/go-urn v1.2.0/go.mod h1:+8+nEpDfqqsY+g338gtMEUOtuK+4dEMhiQEgxpxOKII= 183 | github.com/lunixbochs/vtclean v0.0.0-20180621232353-2d01aacdc34a/go.mod h1:pHhQNgMf3btfWnGBVipUOjRYhoOsdGqdm/+2c2E2WMI= 184 | github.com/magiconair/properties v1.8.1/go.mod h1:PppfXfuXeibc/6YijjN8zIbojt8czPbwD3XqdrwzmxQ= 185 | github.com/manifoldco/promptui v0.8.0/go.mod h1:n4zTdgP0vr0S3w7/O/g98U+e0gwLScEXGwov2nIKuGQ= 186 | github.com/mattn/go-colorable v0.0.9/go.mod h1:9vuHe8Xs5qXnSaW/c/ABM9alt+Vo+STaOChaDxuIBZU= 187 | github.com/mattn/go-colorable v0.1.2/go.mod h1:U0ppj6V5qS13XJ6of8GYAs25YV2eR4EVcfRqFIhoBtE= 188 | github.com/mattn/go-colorable v0.1.4/go.mod h1:U0ppj6V5qS13XJ6of8GYAs25YV2eR4EVcfRqFIhoBtE= 189 | github.com/mattn/go-colorable v0.1.8 h1:c1ghPdyEDarC70ftn0y+A/Ee++9zz8ljHG1b13eJ0s8= 190 | github.com/mattn/go-colorable v0.1.8/go.mod h1:u6P/XSegPjTcexA+o6vUJrdnUu04hMope9wVRipJSqc= 191 | github.com/mattn/go-isatty v0.0.3/go.mod h1:M+lRXTBqGeGNdLjl/ufCoiOlB5xdOkqRJdNxMWT7Zi4= 192 | github.com/mattn/go-isatty v0.0.4/go.mod h1:M+lRXTBqGeGNdLjl/ufCoiOlB5xdOkqRJdNxMWT7Zi4= 193 | github.com/mattn/go-isatty v0.0.8/go.mod h1:Iq45c/XA43vh69/j3iqttzPXn0bhXyGjM0Hdxcsrc5s= 194 | github.com/mattn/go-isatty v0.0.11/go.mod h1:PhnuNfih5lzO57/f3n+odYbM4JtupLOxQOAqxQCu2WE= 195 | github.com/mattn/go-isatty v0.0.12 h1:wuysRhFDzyxgEmMf5xjvJ2M9dZoWAXNNr5LSBS7uHXY= 196 | github.com/mattn/go-isatty v0.0.12/go.mod h1:cbi8OIDigv2wuxKPP5vlRcQ1OAZbq2CE4Kysco4FUpU= 197 | github.com/matttproud/golang_protobuf_extensions v1.0.1/go.mod h1:D8He9yQNgCq6Z5Ld7szi9bcBfOoFv/3dc6xSMkL2PC0= 198 | github.com/miekg/dns v1.0.14/go.mod h1:W1PPwlIAgtquWBMBEV9nkV9Cazfe8ScdGz/Lj7v3Nrg= 199 | github.com/mitchellh/cli v1.0.0/go.mod h1:hNIlj7HEI86fIcpObd7a0FcrxTWetlwJDGcceTlRvqc= 200 | github.com/mitchellh/go-homedir v1.0.0/go.mod h1:SfyaCUpYCn1Vlf4IUYiD9fPX4A5wJrkLzIz1N1q0pr0= 201 | github.com/mitchellh/go-homedir v1.1.0/go.mod h1:SfyaCUpYCn1Vlf4IUYiD9fPX4A5wJrkLzIz1N1q0pr0= 202 | github.com/mitchellh/go-testing-interface v1.0.0/go.mod h1:kRemZodwjscx+RGhAo8eIhFbs2+BFgRtFPeD/KE+zxI= 203 | github.com/mitchellh/gox v0.4.0/go.mod h1:Sd9lOJ0+aimLBi73mGofS1ycjY8lL3uZM3JPS42BGNg= 204 | github.com/mitchellh/iochan v1.0.0/go.mod h1:JwYml1nuB7xOzsp52dPpHFffvOCDupsG0QubkSMEySY= 205 | github.com/mitchellh/mapstructure v0.0.0-20160808181253-ca63d7c062ee/go.mod h1:FVVH3fgwuzCH5S8UJGiWEs2h04kUh9fWfEaFds41c1Y= 206 | github.com/mitchellh/mapstructure v1.1.2/go.mod h1:FVVH3fgwuzCH5S8UJGiWEs2h04kUh9fWfEaFds41c1Y= 207 | github.com/modern-go/concurrent v0.0.0-20180228061459-e0a39a4cb421/go.mod h1:6dJC0mAP4ikYIbvyc7fijjWJddQyLn8Ig3JB5CqoB9Q= 208 | github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd/go.mod h1:6dJC0mAP4ikYIbvyc7fijjWJddQyLn8Ig3JB5CqoB9Q= 209 | github.com/modern-go/reflect2 v0.0.0-20180701023420-4b7aa43c6742/go.mod h1:bx2lNnkwVCuqBIxFjflWJWanXIb3RllmbCylyMrvgv0= 210 | github.com/modern-go/reflect2 v1.0.1/go.mod h1:bx2lNnkwVCuqBIxFjflWJWanXIb3RllmbCylyMrvgv0= 211 | github.com/mwitkow/go-conntrack v0.0.0-20161129095857-cc309e4a2223/go.mod h1:qRWi+5nqEBWmkhHvq77mSJWrCKwh8bxhgT7d/eI7P4U= 212 | github.com/nkovacs/streamquote v0.0.0-20170412213628-49af9bddb229/go.mod h1:0aYXnNPJ8l7uZxf45rWW1a/uME32OF0rhiYGNQ2oF2E= 213 | github.com/oklog/ulid v1.3.1/go.mod h1:CirwcVhetQ6Lv90oh/F+FBtV6XMibvdAFo93nm5qn4U= 214 | github.com/pascaldekloe/goe v0.0.0-20180627143212-57f6aae5913c/go.mod h1:lzWF7FIEvWOWxwDKqyGYQf6ZUaNfKdP144TG7ZOy1lc= 215 | github.com/pelletier/go-toml v1.2.0/go.mod h1:5z9KED0ma1S8pY6P1sdut58dfprrGBbd/94hg7ilaic= 216 | github.com/pkg/browser v0.0.0-20180916011732-0a3d74bf9ce4/go.mod h1:4OwLy04Bl9Ef3GJJCoec+30X3LQs/0/m4HFRt/2LUSA= 217 | github.com/pkg/errors v0.8.0/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0= 218 | github.com/pkg/errors v0.8.1 h1:iURUrRGxPUNPdy5/HRSm+Yj6okJ6UtLINN0Q9M4+h3I= 219 | github.com/pkg/errors v0.8.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0= 220 | github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= 221 | github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= 222 | github.com/posener/complete v1.1.1/go.mod h1:em0nMJCgc9GFtwrmVmEMR/ZL6WyhyjMBndrE9hABlRI= 223 | github.com/prometheus/client_golang v0.9.1/go.mod h1:7SWBe2y4D6OKWSNQJUaRYU/AaXPKyh/dDVn+NZz0KFw= 224 | github.com/prometheus/client_golang v0.9.3/go.mod h1:/TN21ttK/J9q6uSwhBd54HahCDft0ttaMvbicHlPoso= 225 | github.com/prometheus/client_model v0.0.0-20180712105110-5c3871d89910/go.mod h1:MbSGuTsp3dbXC40dX6PRTWyKYBIrTGTE9sqQNg2J8bo= 226 | github.com/prometheus/client_model v0.0.0-20190129233127-fd36f4220a90/go.mod h1:xMI15A0UPsDsEKsMN9yxemIoYk6Tm2C1GtYGdfGttqA= 227 | github.com/prometheus/client_model v0.0.0-20190812154241-14fe0d1b01d4/go.mod h1:xMI15A0UPsDsEKsMN9yxemIoYk6Tm2C1GtYGdfGttqA= 228 | github.com/prometheus/common v0.0.0-20181113130724-41aa239b4cce/go.mod h1:daVV7qP5qjZbuso7PdcryaAu0sAZbrN9i7WWcTMWvro= 229 | github.com/prometheus/common v0.4.0/go.mod h1:TNfzLD0ON7rHzMJeJkieUDPYmFC7Snx/y86RQel1bk4= 230 | github.com/prometheus/procfs v0.0.0-20181005140218-185b4288413d/go.mod h1:c3At6R/oaqEKCNdg8wHV1ftS6bRYblBhIjjI8uT2IGk= 231 | github.com/prometheus/procfs v0.0.0-20190507164030-5867b95ac084/go.mod h1:TjEm7ze935MbeOT/UhFTIMYKhuLP4wbCsTZCD3I8kEA= 232 | github.com/prometheus/tsdb v0.7.1/go.mod h1:qhTCs0VvXwvX/y3TZrWD7rabWM+ijKTux40TwIPHuXU= 233 | github.com/rjeczalik/notify v0.9.2/go.mod h1:aErll2f0sUX9PXZnVNyeiObbmTlk5jnMoCa4QEjJeqM= 234 | github.com/rogpeppe/fastuuid v0.0.0-20150106093220-6724a57986af/go.mod h1:XWv6SoW27p1b0cqNHllgS5HIMJraePCO15w5zCzIWYg= 235 | github.com/rogpeppe/go-internal v1.3.0/go.mod h1:M8bDsm7K2OlrFYOpmOWEs/qY81heoFRclV5y23lUDJ4= 236 | github.com/russross/blackfriday/v2 v2.0.1/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM= 237 | github.com/russross/blackfriday/v2 v2.1.0 h1:JIOH55/0cWyOuilr9/qlrm0BSXldqnqwMsf35Ld67mk= 238 | github.com/russross/blackfriday/v2 v2.1.0/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM= 239 | github.com/ryanuber/columnize v0.0.0-20160712163229-9b3edd62028f/go.mod h1:sm1tb6uqfes/u+d4ooFouqFdy9/2g9QGwK3SQygK0Ts= 240 | github.com/sean-/seed v0.0.0-20170313163322-e2103e2c3529/go.mod h1:DxrIzT+xaE7yg65j358z/aeFdxmN0P9QXhEzd20vsDc= 241 | github.com/sergi/go-diff v1.0.0/go.mod h1:0CfEIISq7TuYL3j771MWULgwwjU+GofnZX9QAmXWZgo= 242 | github.com/shurcooL/sanitized_anchor_name v1.0.0/go.mod h1:1NzhyTcUVG4SuEtjjoZeVRXNmyL/1OwPU0+IJeTBvfc= 243 | github.com/sirupsen/logrus v1.2.0/go.mod h1:LxeOpSwHxABJmUn/MG1IvRgCAasNZTLOkJPxbbu5VWo= 244 | github.com/smartystreets/assertions v0.0.0-20180927180507-b2de0cb4f26d/go.mod h1:OnSkiWE9lh6wB0YB77sQom3nweQdgAjqCqsofrRNTgc= 245 | github.com/smartystreets/goconvey v1.6.4/go.mod h1:syvi0/a8iFYH4r/RixwvyeAJjdLS9QV7WQ/tjFTllLA= 246 | github.com/soheilhy/cmux v0.1.4/go.mod h1:IM3LyeVVIOuxMH7sFAkER9+bJ4dT7Ms6E4xg4kGIyLM= 247 | github.com/spaolacci/murmur3 v0.0.0-20180118202830-f09979ecbc72/go.mod h1:JwIasOWyU6f++ZhiEuf87xNszmSA2myDM2Kzu9HwQUA= 248 | github.com/spf13/afero v1.1.2/go.mod h1:j4pytiNVoe2o6bmDsKpLACNPDBIoEAkihy7loJ1B0CQ= 249 | github.com/spf13/cast v1.3.0/go.mod h1:Qx5cxh0v+4UWYiBimWS+eyWzqEqokIECu5etghLkUJE= 250 | github.com/spf13/cobra v1.1.3/go.mod h1:pGADOWyqRD/YMrPZigI/zbliZ2wVD/23d+is3pSWzOo= 251 | github.com/spf13/cobra v1.4.0 h1:y+wJpx64xcgO1V+RcnwW0LEHxTKRi2ZDPSBjWnrg88Q= 252 | github.com/spf13/cobra v1.4.0/go.mod h1:Wo4iy3BUC+X2Fybo0PDqwJIv3dNRiZLHQymsfxlB84g= 253 | github.com/spf13/jwalterweatherman v1.0.0/go.mod h1:cQK4TGJAtQXfYWX+Ddv3mKDzgVb68N+wFjFa4jdeBTo= 254 | github.com/spf13/pflag v1.0.3/go.mod h1:DYY7MBk1bdzusC3SYhjObp+wFpr4gzcvqqNjLnInEg4= 255 | github.com/spf13/pflag v1.0.5 h1:iy+VFUOCP1a+8yFto/drg2CJ5u0yRoB7fZw3DKv/JXA= 256 | github.com/spf13/pflag v1.0.5/go.mod h1:McXfInJRrz4CZXVZOBLb0bTZqETkiAhM9Iw0y3An2Bg= 257 | github.com/spf13/viper v1.7.0/go.mod h1:8WkrPz2fc9jxqZNCJI/76HCieCp4Q8HaLFoCha5qpdg= 258 | github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= 259 | github.com/stretchr/objx v0.1.1/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= 260 | github.com/stretchr/objx v0.5.2 h1:xuMeJ0Sdp5ZMRXx/aWO6RZxdr3beISkG5/G/aIRr3pY= 261 | github.com/stretchr/objx v0.5.2/go.mod h1:FRsXN1f5AsAjCGJKqEizvkpNtU+EGNCLh3NxZ/8L+MA= 262 | github.com/stretchr/testify v1.2.1/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs= 263 | github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs= 264 | github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI= 265 | github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81PSLYec5m4= 266 | github.com/stretchr/testify v1.6.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= 267 | github.com/stretchr/testify v1.9.0 h1:HtqpIVDClZ4nwg75+f6Lvsy/wHu+3BoSGCbBAcpTsTg= 268 | github.com/stretchr/testify v1.9.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY= 269 | github.com/subosito/gotenv v1.2.0/go.mod h1:N0PQaV/YGNqwC0u51sEeR/aUtSLEXKX9iv69rRypqCw= 270 | github.com/tatsushid/go-fastping v0.0.0-20160109021039-d7bb493dee3e h1:nt2877sKfojlHCTOBXbpWjBkuWKritFaGIfgQwbQUls= 271 | github.com/tatsushid/go-fastping v0.0.0-20160109021039-d7bb493dee3e/go.mod h1:B4+Kq1u5FlULTjFSM707Q6e/cOHFv0z/6QRoxubDIQ8= 272 | github.com/tmc/grpc-websocket-proxy v0.0.0-20190109142713-0ad062ec5ee5/go.mod h1:ncp9v5uamzpCO7NfCPTXjqaC+bZgJeR0sMTm6dMHP7U= 273 | github.com/ugorji/go v1.1.7/go.mod h1:kZn38zHttfInRq0xu/PH0az30d+z6vm202qpg1oXVMw= 274 | github.com/ugorji/go/codec v1.1.7/go.mod h1:Ax+UKWsSmolVDwsd+7N3ZtXu+yMGCf907BLYF3GoBXY= 275 | github.com/valyala/bytebufferpool v1.0.0/go.mod h1:6bBcMArwyJ5K/AmCkWv1jt77kVWyCJ6HpOuEn7z0Csc= 276 | github.com/valyala/fasttemplate v1.0.1/go.mod h1:UQGH1tvbgY+Nz5t2n7tXsz52dQxojPUpymEIMZ47gx8= 277 | github.com/xiang90/probing v0.0.0-20190116061207-43a291ad63a2/go.mod h1:UETIi67q53MR2AWcXfiuqkDkRtnGDLqkBTpCHuJHxtU= 278 | go.coder.com/cli v0.4.0/go.mod h1:hRTOURCR3LJF1FRW9arecgrzX+AHG7mfYMwThPIgq+w= 279 | go.coder.com/flog v0.0.0-20190906214207-47dd47ea0512/go.mod h1:83JsYgXYv0EOaXjIMnaZ1Fl6ddNB3fJnDZ/8845mUJ8= 280 | go.etcd.io/bbolt v1.3.2/go.mod h1:IbVyRI1SCnLcuJnV2u8VeU0CEYM7e686BmAb1XKL+uU= 281 | go.opencensus.io v0.21.0/go.mod h1:mSImk1erAIZhrmZN+AvHh14ztQfjbGwt4TtuofqLduU= 282 | go.opencensus.io v0.22.0/go.mod h1:+kGneAE2xo2IficOXnaByMWTGM9T73dGwxeWcUqIpI8= 283 | go.opencensus.io v0.22.2 h1:75k/FF0Q2YM8QYo07VPddOLBslDt1MZOdEslOHvmzAs= 284 | go.opencensus.io v0.22.2/go.mod h1:yxeiOL68Rb0Xd1ddK5vPZ/oVn4vY4Ynel7k9FzqtOIw= 285 | go.uber.org/atomic v1.4.0/go.mod h1:gD2HeocX3+yG+ygLZcrzQJaqmWj9AIm7n08wl/qW/PE= 286 | go.uber.org/multierr v1.1.0/go.mod h1:wR5kodmAFQ0UK8QlbwjlSNy0Z68gJhDJUG5sjR94q/0= 287 | go.uber.org/zap v1.10.0/go.mod h1:vwi/ZaCAaUcBkycHslxD9B2zi4UTXhF60s6SWpuDF0Q= 288 | golang.org/x/crypto v0.0.0-20180904163835-0709b304e793/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4= 289 | golang.org/x/crypto v0.0.0-20181029021203-45a5f77698d3/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4= 290 | golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w= 291 | golang.org/x/crypto v0.0.0-20190510104115-cbcb75029529/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI= 292 | golang.org/x/crypto v0.0.0-20190605123033-f99c8df09eb5/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI= 293 | golang.org/x/crypto v0.0.0-20191206172530-e9b2fee46413/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto= 294 | golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto= 295 | golang.org/x/crypto v0.31.0 h1:ihbySMvVjLAeSH1IbfcRTkD/iNscyz8rGzjF/E5hV6U= 296 | golang.org/x/crypto v0.31.0/go.mod h1:kDsLvtWBEx7MV9tJOj9bnXsPbxwJQ6csT/x4KIN4Ssk= 297 | golang.org/x/exp v0.0.0-20190121172915-509febef88a4/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA= 298 | golang.org/x/exp v0.0.0-20190306152737-a1d7652674e8/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA= 299 | golang.org/x/exp v0.0.0-20190510132918-efd6b22b2522/go.mod h1:ZjyILWgesfNpC6sMxTJOJm9Kp84zZh5NQWvqDGG3Qr8= 300 | golang.org/x/exp v0.0.0-20190829153037-c13cbed26979/go.mod h1:86+5VVa7VpoJ4kLfm080zCjGlMRFzhUhsZKEZO7MGek= 301 | golang.org/x/exp v0.0.0-20191030013958-a1ab85dbe136/go.mod h1:JXzH8nQsPlswgeRAPE3MuO9GYsAcnJvJ4vnMwN/5qkY= 302 | golang.org/x/image v0.0.0-20190227222117-0694c2d4d067/go.mod h1:kZ7UVZpmo3dzQBMxlp+ypCbDeSB+sBbTgSJuh5dn5js= 303 | golang.org/x/image v0.0.0-20190802002840-cff245a6509b/go.mod h1:FeLwcggjj3mMvU+oOTbSwawSJRM1uh48EjtB4UJZlP0= 304 | golang.org/x/lint v0.0.0-20181026193005-c67002cb31c3/go.mod h1:UVdnD1Gm6xHRNCYTkRU2/jEulfH38KcIWyp/GAMgvoE= 305 | golang.org/x/lint v0.0.0-20190227174305-5b3e6a55c961/go.mod h1:wehouNa3lNwaWXcvxsM5YxQ5yQlVC4a0KAMCusXpPoU= 306 | golang.org/x/lint v0.0.0-20190301231843-5614ed5bae6f/go.mod h1:UVdnD1Gm6xHRNCYTkRU2/jEulfH38KcIWyp/GAMgvoE= 307 | golang.org/x/lint v0.0.0-20190313153728-d0100b6bd8b3/go.mod h1:6SW0HCj/g11FgYtHlgUYUwCkIfeOF89ocIRzGO/8vkc= 308 | golang.org/x/lint v0.0.0-20190409202823-959b441ac422/go.mod h1:6SW0HCj/g11FgYtHlgUYUwCkIfeOF89ocIRzGO/8vkc= 309 | golang.org/x/lint v0.0.0-20190909230951-414d861bb4ac/go.mod h1:6SW0HCj/g11FgYtHlgUYUwCkIfeOF89ocIRzGO/8vkc= 310 | golang.org/x/lint v0.0.0-20190930215403-16217165b5de/go.mod h1:6SW0HCj/g11FgYtHlgUYUwCkIfeOF89ocIRzGO/8vkc= 311 | golang.org/x/mobile v0.0.0-20190312151609-d3739f865fa6/go.mod h1:z+o9i4GpDbdi3rU15maQ/Ox0txvL9dWGYEHz965HBQE= 312 | golang.org/x/mobile v0.0.0-20190719004257-d2bd2a29d028/go.mod h1:E/iHnbuqvinMTCcRqshq8CkpyQDoeVncDDYHnLhea+o= 313 | golang.org/x/mod v0.0.0-20190513183733-4bf6d317e70e/go.mod h1:mXi4GBBbnImb6dmsKGUJ2LatrhH/nqhxcFungHvyanc= 314 | golang.org/x/mod v0.1.0/go.mod h1:0QHyrYULN0/3qlju5TqG8bIK38QM8yzMo5ekMj3DlcY= 315 | golang.org/x/net v0.0.0-20180724234803-3673e40ba225/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= 316 | golang.org/x/net v0.0.0-20180826012351-8a410e7b638d/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= 317 | golang.org/x/net v0.0.0-20181023162649-9b4f9f5ad519/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= 318 | golang.org/x/net v0.0.0-20181114220301-adae6a3d119a/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= 319 | golang.org/x/net v0.0.0-20181201002055-351d144fa1fc/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= 320 | golang.org/x/net v0.0.0-20181220203305-927f97764cc3/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= 321 | golang.org/x/net v0.0.0-20190108225652-1e06a53dbb7e/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= 322 | golang.org/x/net v0.0.0-20190213061140-3a22650c66bd/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= 323 | golang.org/x/net v0.0.0-20190311183353-d8887717615a/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg= 324 | golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg= 325 | golang.org/x/net v0.0.0-20190501004415-9ce7a6920f09/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg= 326 | golang.org/x/net v0.0.0-20190503192946-f4e77d36d62c/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg= 327 | golang.org/x/net v0.0.0-20190603091049-60506f45cf65/go.mod h1:HSz+uSET+XFnRR8LxR5pz3Of3rY3CfYBVs4xY44aLks= 328 | golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= 329 | golang.org/x/net v0.0.0-20191209160850-c0dbc17a3553/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= 330 | golang.org/x/net v0.0.0-20200822124328-c89045814202/go.mod h1:/O7V0waA8r7cgGh81Ro3o1hOxt32SMVPicZroKQ2sZA= 331 | golang.org/x/net v0.25.0 h1:d/OCCoBEUq33pjydKrGQhw7IlUPI2Oylr+8qLx49kac= 332 | golang.org/x/net v0.25.0/go.mod h1:JkAGAh7GEvH74S6FOH42FLoXpXbE/aqXSrIQjXgsiwM= 333 | golang.org/x/oauth2 v0.0.0-20180821212333-d2e6202438be/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U= 334 | golang.org/x/oauth2 v0.0.0-20190226205417-e64efc72b421/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw= 335 | golang.org/x/oauth2 v0.0.0-20190604053449-0f29369cfe45/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw= 336 | golang.org/x/sync v0.0.0-20180314180146-1d60e4601c6f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= 337 | golang.org/x/sync v0.0.0-20181108010431-42b317875d0f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= 338 | golang.org/x/sync v0.0.0-20181221193216-37e7f081c4d4/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= 339 | golang.org/x/sync v0.0.0-20190227155943-e225da77a7e6/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= 340 | golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= 341 | golang.org/x/sync v0.0.0-20200625203802-6e8e738ad208/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= 342 | golang.org/x/sys v0.0.0-20180823144017-11551d06cbcc/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= 343 | golang.org/x/sys v0.0.0-20180830151530-49385e6e1522/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= 344 | golang.org/x/sys v0.0.0-20180905080454-ebe1bf3edb33/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= 345 | golang.org/x/sys v0.0.0-20180926160741-c2ed4eda69e7/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= 346 | golang.org/x/sys v0.0.0-20181026203630-95b1ffbd15a5/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= 347 | golang.org/x/sys v0.0.0-20181107165924-66b7b1311ac8/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= 348 | golang.org/x/sys v0.0.0-20181116152217-5ac8a444bdc5/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= 349 | golang.org/x/sys v0.0.0-20181122145206-62eef0e2fa9b/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= 350 | golang.org/x/sys v0.0.0-20181128092732-4ed8d59d0b35/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= 351 | golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= 352 | golang.org/x/sys v0.0.0-20190222072716-a9d3bda3a223/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= 353 | golang.org/x/sys v0.0.0-20190312061237-fead79001313/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= 354 | golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= 355 | golang.org/x/sys v0.0.0-20190502145724-3ef323f4f1fd/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= 356 | golang.org/x/sys v0.0.0-20190507160741-ecd444e8653b/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= 357 | golang.org/x/sys v0.0.0-20190606165138-5da285871e9c/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= 358 | golang.org/x/sys v0.0.0-20190624142023-c5567b49c5d0/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= 359 | golang.org/x/sys v0.0.0-20191026070338-33540a1f6037/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= 360 | golang.org/x/sys v0.0.0-20191210023423-ac6580df4449/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= 361 | golang.org/x/sys v0.0.0-20200116001909-b77594299b42/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= 362 | golang.org/x/sys v0.0.0-20200223170610-d5e6a3e2c0ae/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= 363 | golang.org/x/sys v0.0.0-20200323222414-85ca7c5b95cd/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= 364 | golang.org/x/sys v0.0.0-20201018230417-eeed37f84f13/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= 365 | golang.org/x/sys v0.28.0 h1:Fksou7UEQUWlKvIdsqzJmUmCX3cZuD2+P3XyyzwMhlA= 366 | golang.org/x/sys v0.28.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= 367 | golang.org/x/term v0.27.0 h1:WP60Sv1nlK1T6SupCHbXzSaN0b9wUmsPoRS9b61A23Q= 368 | golang.org/x/term v0.27.0/go.mod h1:iMsnZpn0cago0GOrHO2+Y7u7JPn5AylBrcoWkElMTSM= 369 | golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= 370 | golang.org/x/text v0.3.1-0.20180807135948-17ff2d5776d2/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= 371 | golang.org/x/text v0.3.2/go.mod h1:bEr9sfX3Q8Zfm5fL9x+3itogRgK3+ptLWKqgva+5dAk= 372 | golang.org/x/time v0.0.0-20181108054448-85acf8d2951c/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ= 373 | golang.org/x/time v0.0.0-20190308202827-9d24e82272b4/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ= 374 | golang.org/x/time v0.0.0-20191024005414-555d28b269f0/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ= 375 | golang.org/x/tools v0.0.0-20180221164845-07fd8470d635/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= 376 | golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= 377 | golang.org/x/tools v0.0.0-20190114222345-bf090417da8b/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= 378 | golang.org/x/tools v0.0.0-20190226205152-f727befe758c/go.mod h1:9Yl7xja0Znq3iFh3HoIrodX9oNMXvdceNzlUR8zjMvY= 379 | golang.org/x/tools v0.0.0-20190311212946-11955173bddd/go.mod h1:LCzVGOaR6xXOjkQ3onu1FJEFr0SW1gC7cKk1uF8kGRs= 380 | golang.org/x/tools v0.0.0-20190312151545-0bb0c0a6e846/go.mod h1:LCzVGOaR6xXOjkQ3onu1FJEFr0SW1gC7cKk1uF8kGRs= 381 | golang.org/x/tools v0.0.0-20190312170243-e65039ee4138/go.mod h1:LCzVGOaR6xXOjkQ3onu1FJEFr0SW1gC7cKk1uF8kGRs= 382 | golang.org/x/tools v0.0.0-20190328211700-ab21143f2384/go.mod h1:LCzVGOaR6xXOjkQ3onu1FJEFr0SW1gC7cKk1uF8kGRs= 383 | golang.org/x/tools v0.0.0-20190425150028-36563e24a262/go.mod h1:RgjU9mgBXZiqYHBnxXauZ1Gv1EHHAz9KjViQ78xBX0Q= 384 | golang.org/x/tools v0.0.0-20190506145303-2d16b83fe98c/go.mod h1:RgjU9mgBXZiqYHBnxXauZ1Gv1EHHAz9KjViQ78xBX0Q= 385 | golang.org/x/tools v0.0.0-20190524140312-2c0ae7006135/go.mod h1:RgjU9mgBXZiqYHBnxXauZ1Gv1EHHAz9KjViQ78xBX0Q= 386 | golang.org/x/tools v0.0.0-20190606124116-d0a3d012864b/go.mod h1:/rFqwRUd4F7ZHNgwSSTFct+R/Kf4OFW1sUzUTQQTgfc= 387 | golang.org/x/tools v0.0.0-20190621195816-6e04913cbbac/go.mod h1:/rFqwRUd4F7ZHNgwSSTFct+R/Kf4OFW1sUzUTQQTgfc= 388 | golang.org/x/tools v0.0.0-20190628153133-6cdbf07be9d0/go.mod h1:/rFqwRUd4F7ZHNgwSSTFct+R/Kf4OFW1sUzUTQQTgfc= 389 | golang.org/x/tools v0.0.0-20190816200558-6889da9d5479/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= 390 | golang.org/x/tools v0.0.0-20190911174233-4f2ddba30aff/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= 391 | golang.org/x/tools v0.0.0-20191012152004-8de300cfc20a/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= 392 | golang.org/x/tools v0.0.0-20191112195655-aa38f8e97acc/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= 393 | golang.org/x/tools v0.0.0-20191115202509-3a792d9c32b2/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= 394 | golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= 395 | golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= 396 | golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1 h1:go1bK/D/BFZV2I8cIQd1NKEZ+0owSTG1fDTci4IqFcE= 397 | golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= 398 | google.golang.org/api v0.4.0/go.mod h1:8k5glujaEP+g9n7WNsDg8QP6cUVNI86fCNMcbazEtwE= 399 | google.golang.org/api v0.7.0/go.mod h1:WtwebWUNSVBH/HAw79HIFXZNqEvBhG+Ra+ax0hx3E3M= 400 | google.golang.org/api v0.8.0/go.mod h1:o4eAsZoiT+ibD93RtjEohWalFOjRDx6CVaqeizhEnKg= 401 | google.golang.org/api v0.9.0/go.mod h1:o4eAsZoiT+ibD93RtjEohWalFOjRDx6CVaqeizhEnKg= 402 | google.golang.org/api v0.13.0/go.mod h1:iLdEw5Ide6rF15KTC1Kkl0iskquN2gFfn9o9XIsbkAI= 403 | google.golang.org/api v0.14.0/go.mod h1:iLdEw5Ide6rF15KTC1Kkl0iskquN2gFfn9o9XIsbkAI= 404 | google.golang.org/appengine v1.1.0/go.mod h1:EbEs0AVv82hx2wNQdGPgUI5lhzA/G0D9YwlJXL52JkM= 405 | google.golang.org/appengine v1.4.0/go.mod h1:xpcJRLb0r/rnEns0DIKYYv+WjYCduHsrkT7/EB5XEv4= 406 | google.golang.org/appengine v1.5.0/go.mod h1:xpcJRLb0r/rnEns0DIKYYv+WjYCduHsrkT7/EB5XEv4= 407 | google.golang.org/appengine v1.6.1/go.mod h1:i06prIuMbXzDqacNJfV5OdTW448YApPu5ww/cMBSeb0= 408 | google.golang.org/genproto v0.0.0-20180817151627-c66870c02cf8/go.mod h1:JiN7NxoALGmiZfu7CAH4rXhgtRTLTxftemlI0sWmxmc= 409 | google.golang.org/genproto v0.0.0-20190307195333-5fe7a883aa19/go.mod h1:VzzqZJRnGkLBvHegQrXjBqPurQTc5/KpmUdxsrq26oE= 410 | google.golang.org/genproto v0.0.0-20190418145605-e7d98fc518a7/go.mod h1:VzzqZJRnGkLBvHegQrXjBqPurQTc5/KpmUdxsrq26oE= 411 | google.golang.org/genproto v0.0.0-20190425155659-357c62f0e4bb/go.mod h1:VzzqZJRnGkLBvHegQrXjBqPurQTc5/KpmUdxsrq26oE= 412 | google.golang.org/genproto v0.0.0-20190502173448-54afdca5d873/go.mod h1:VzzqZJRnGkLBvHegQrXjBqPurQTc5/KpmUdxsrq26oE= 413 | google.golang.org/genproto v0.0.0-20190801165951-fa694d86fc64/go.mod h1:DMBHOl98Agz4BDEuKkezgsaosCRResVns1a3J2ZsMNc= 414 | google.golang.org/genproto v0.0.0-20190819201941-24fa4b261c55/go.mod h1:DMBHOl98Agz4BDEuKkezgsaosCRResVns1a3J2ZsMNc= 415 | google.golang.org/genproto v0.0.0-20190911173649-1774047e7e51/go.mod h1:IbNlFCBrqXvoKpeg0TB2l7cyZUmoaFKYIwrEpbDKLA8= 416 | google.golang.org/genproto v0.0.0-20191108220845-16a3f7862a1a/go.mod h1:n3cpQtvxv34hfy77yVDNjmbRyujviMdxYliBSkLhpCc= 417 | google.golang.org/genproto v0.0.0-20191115194625-c23dd37a84c9/go.mod h1:n3cpQtvxv34hfy77yVDNjmbRyujviMdxYliBSkLhpCc= 418 | google.golang.org/genproto v0.0.0-20191216164720-4f79533eabd1/go.mod h1:n3cpQtvxv34hfy77yVDNjmbRyujviMdxYliBSkLhpCc= 419 | google.golang.org/grpc v1.19.0/go.mod h1:mqu4LbDTu4XGKhr4mRzUsmM4RtVoemTSY81AxZiDr8c= 420 | google.golang.org/grpc v1.20.1/go.mod h1:10oTOabMzJvdu6/UiuZezV6QK5dSlG84ov/aaiqXj38= 421 | google.golang.org/grpc v1.21.1/go.mod h1:oYelfM1adQP15Ek0mdvEgi9Df8B9CZIaU1084ijfRaM= 422 | google.golang.org/grpc v1.23.0/go.mod h1:Y5yQAOtifL1yxbo5wqy6BxZv8vAUGQwXBOALyacEbxg= 423 | google.golang.org/grpc v1.25.1/go.mod h1:c3i+UQWmh7LiEpx4sFZnkU36qjEYZ0imhYfXVyQciAY= 424 | gopkg.in/alecthomas/kingpin.v2 v2.2.6/go.mod h1:FMv+mEhP44yOT+4EoQTLFTRgOQ1FBLkstjWtayDeSgw= 425 | gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= 426 | gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127 h1:qIbj1fsPNlZgppZ+VLlY7N33q108Sa+fhmuc+sWQYwY= 427 | gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= 428 | gopkg.in/errgo.v2 v2.1.0/go.mod h1:hNsd1EY+bozCKY1Ytp96fpM3vjJbqLJn88ws8XvfDNI= 429 | gopkg.in/ini.v1 v1.51.0/go.mod h1:pNLf8WUiyNEtQjuu5G5vTm06TEv9tsIgeAvK8hOrP4k= 430 | gopkg.in/resty.v1 v1.12.0/go.mod h1:mDo4pnntr5jdWRML875a/NmxYqAlA73dVijT2AXvQQo= 431 | gopkg.in/yaml.v2 v2.0.0-20170812160011-eb3733d160e7/go.mod h1:JAlM8MvJe8wmxCU4Bli9HhUf9+ttbYbLASfIpnQbh74= 432 | gopkg.in/yaml.v2 v2.2.1/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= 433 | gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= 434 | gopkg.in/yaml.v2 v2.2.4/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= 435 | gopkg.in/yaml.v2 v2.2.8/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= 436 | gopkg.in/yaml.v2 v2.4.0 h1:D8xgwECY7CYvx+Y2n4sBz93Jn9JRvxdiyyo8CTfuKaY= 437 | gopkg.in/yaml.v2 v2.4.0/go.mod h1:RDklbk79AGWmwhnvt/jBztapEOGDOx6ZbXqjP6csGnQ= 438 | gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= 439 | gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA= 440 | gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= 441 | honnef.co/go/tools v0.0.0-20190102054323-c2f93a96b099/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4= 442 | honnef.co/go/tools v0.0.0-20190106161140-3f1c8253044a/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4= 443 | honnef.co/go/tools v0.0.0-20190418001031-e561f6794a2a/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4= 444 | honnef.co/go/tools v0.0.0-20190523083050-ea95bdfd59fc/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4= 445 | honnef.co/go/tools v0.0.1-2019.2.3/go.mod h1:a3bituU0lyd329TUQxRnasdCoJDkEUEAqEt0JzvZhAg= 446 | nhooyr.io/websocket v1.8.6/go.mod h1:B70DZP8IakI65RVQ51MsWP/8jndNma26DVA/nFSCgW0= 447 | rsc.io/binaryregexp v0.2.0/go.mod h1:qTv7/COck+e2FymRvadv62gMdZztPaShugOCi3I+8D8= 448 | -------------------------------------------------------------------------------- /internal/encoder/encoder.go: -------------------------------------------------------------------------------- 1 | package encoder 2 | 3 | import ( 4 | "encoding/json" 5 | "io" 6 | 7 | "cdr.dev/coder-cli/pkg/tablewriter" 8 | "gopkg.in/yaml.v3" 9 | ) 10 | 11 | // Encoder can encode generic objects into various output formats. 12 | type Encoder[T any] struct { 13 | w io.Writer 14 | output string 15 | } 16 | 17 | // New initializes a new Encoder. 18 | func New[T any](w io.Writer, output string) Encoder[T] { 19 | return Encoder[T]{w, output} 20 | } 21 | 22 | // Encode encodes the generic objects into the output specified during Encoder initialization. 23 | func (e *Encoder[T]) Encode(objects ...T) error { 24 | var err error 25 | switch e.output { 26 | case "json": 27 | jsonEncoder := json.NewEncoder(e.w) 28 | jsonEncoder.SetIndent("", "\t") 29 | jsonEncoder.SetEscapeHTML(true) 30 | // Don't output as json array if there is only one object 31 | if len(objects) == 1 { 32 | err = jsonEncoder.Encode(objects[0]) 33 | } else { 34 | err = jsonEncoder.Encode(objects) 35 | } 36 | case "yaml": 37 | err = yaml.NewEncoder(e.w).Encode(objects) 38 | default: 39 | err = tablewriter.WriteTable(e.w, len(objects), 40 | func(i int) any { 41 | return objects[i] 42 | }, 43 | ) 44 | } 45 | return err 46 | } 47 | -------------------------------------------------------------------------------- /internal/encoder/encoder_test.go: -------------------------------------------------------------------------------- 1 | package encoder 2 | 3 | import ( 4 | "bytes" 5 | "encoding/json" 6 | "testing" 7 | 8 | "github.com/stretchr/testify/require" 9 | ) 10 | 11 | func TestEncoder(t *testing.T) { 12 | type testObject struct { 13 | Field1 string `json:"field_1" yaml:"field_1" table:"FIELD_1"` 14 | Field2 int `json:"field_2" yaml:"field_2" table:"FIELD_2"` 15 | } 16 | 17 | for _, test := range []struct { 18 | name string 19 | output string 20 | object testObject 21 | assertExpected func(b []byte) 22 | }{ 23 | { 24 | name: "encode as json", 25 | output: "json", 26 | object: testObject{ 27 | Field1: "a", 28 | Field2: 1, 29 | }, 30 | assertExpected: func(b []byte) { 31 | o := new(testObject) 32 | require.NoError(t, json.Unmarshal(b, o)) 33 | require.Equal(t, "a", o.Field1) 34 | require.Equal(t, 1, o.Field2) 35 | }, 36 | }, 37 | { 38 | name: "encode as yaml", 39 | output: "yaml", 40 | object: testObject{ 41 | Field1: "b", 42 | Field2: 2, 43 | }, 44 | assertExpected: func(b []byte) { 45 | expected := "- field_1: b\n field_2: 2\n" 46 | require.Equal(t, expected, string(b)) 47 | }, 48 | }, 49 | { 50 | name: "encode as table", 51 | object: testObject{ 52 | Field1: "c", 53 | Field2: 3, 54 | }, 55 | assertExpected: func(b []byte) { 56 | expected := "FIELD_1 FIELD_2 \nc 3 \n" 57 | require.Equal(t, expected, string(b)) 58 | }, 59 | }, 60 | } { 61 | t.Run(test.name, func(t *testing.T) { 62 | buf := bytes.NewBuffer(nil) 63 | enc := New[testObject](buf, test.output) 64 | require.NoError(t, enc.Encode(test.object)) 65 | test.assertExpected(buf.Bytes()) 66 | }) 67 | } 68 | } 69 | -------------------------------------------------------------------------------- /internal/list/list.go: -------------------------------------------------------------------------------- 1 | package list 2 | 3 | import ( 4 | "context" 5 | "errors" 6 | "fmt" 7 | "io" 8 | "net" 9 | "net/http" 10 | "strings" 11 | "sync" 12 | "time" 13 | 14 | gw "github.com/jackpal/gateway" 15 | goping "github.com/tatsushid/go-fastping" 16 | 17 | "github.com/fuskovic/networker/v3/internal/resolve" 18 | ) 19 | 20 | const ( 21 | notAvailable = "N/A" 22 | icmpIpv4 = "ip4:icmp" 23 | icmpIpv6 = "ip6:ipv6-icmp" 24 | ) 25 | 26 | const ( 27 | DeviceKindUnknown Kind = "unknown" 28 | DeviceKindRouter Kind = "router" 29 | DeviceKindCurrent Kind = "current-device" 30 | DeviceKindPeer Kind = "peer" 31 | ) 32 | 33 | type Kind string 34 | 35 | type Device struct { 36 | Kind Kind `json:"kind" table:"KIND"` 37 | Hostname string `json:"hostname" table:"HOSTNAME"` 38 | LocalIP net.IP `json:"local_ip" table:"LOCAL_IP"` 39 | RemoteIP net.IP `json:"remote_ip,omitempty" table:"REMOTE_IP"` 40 | Up bool `json:"up" yaml:"up" table:"UP"` 41 | } 42 | 43 | // Devices lists all of the devices on the local network. 44 | func Devices(ctx context.Context) ([]Device, error) { 45 | cidr, err := getCIDR(ctx) 46 | if err != nil { 47 | return nil, fmt.Errorf("failed to get cidr: %w", err) 48 | } 49 | 50 | router, err := getRouter(ctx) 51 | if err != nil { 52 | return nil, fmt.Errorf("failed to get router: %w", err) 53 | } 54 | 55 | hostIPs, err := getHosts(ctx, cidr, router) 56 | if err != nil { 57 | return nil, fmt.Errorf("failed to get hosts: %w", err) 58 | } 59 | 60 | currentDevice, err := getCurrentDevice(ctx) 61 | if err != nil { 62 | return nil, fmt.Errorf("failed to get current device: %w", err) 63 | } 64 | 65 | hostIPs = removeIP(currentDevice.LocalIP.String(), hostIPs) 66 | 67 | var ( 68 | devices = []Device{*router, *currentDevice} 69 | wg = sync.WaitGroup{} 70 | mutex = sync.Mutex{} 71 | ) 72 | 73 | for _, hostIP := range dedupe(hostIPs) { 74 | wg.Add(1) 75 | go func(ip string) { 76 | defer wg.Done() 77 | 78 | device, err := getDevice(ctx, ip) 79 | if err != nil || device == nil { 80 | return 81 | } 82 | device.Up = ping(ip) 83 | 84 | mutex.Lock() 85 | devices = append(devices, *device) 86 | mutex.Unlock() 87 | }(hostIP) 88 | } 89 | wg.Wait() 90 | return devices, nil 91 | } 92 | 93 | func getDevice(_ context.Context, ip string) (*Device, error) { 94 | ipAddr := net.ParseIP(ip) 95 | if ipAddr == nil { 96 | return nil, fmt.Errorf("failed to parse ip %q", ip) 97 | } 98 | 99 | return &Device{ 100 | LocalIP: ipAddr, 101 | Hostname: resolve.Hostname(ipAddr), 102 | Kind: DeviceKindPeer, 103 | }, nil 104 | } 105 | 106 | func getCurrentDevice(_ context.Context) (*Device, error) { 107 | localIP, err := getCurrentDeviceLocalIP() 108 | if err != nil { 109 | return nil, fmt.Errorf("failed to get local ip of current device: %w", err) 110 | } 111 | 112 | remoteIP, err := getCurrentDeviceRemoteIP() 113 | if err != nil { 114 | return nil, fmt.Errorf("failed to get remote ip of current device: %w", err) 115 | } 116 | 117 | return &Device{ 118 | LocalIP: localIP, 119 | RemoteIP: remoteIP, 120 | Hostname: resolve.Hostname(localIP), 121 | Kind: DeviceKindCurrent, 122 | Up: true, 123 | }, nil 124 | } 125 | 126 | func getRouter(_ context.Context) (*Device, error) { 127 | ipAddr, err := gw.DiscoverGateway() 128 | if err != nil { 129 | return nil, fmt.Errorf("failed to discover gateway: %w", err) 130 | } 131 | 132 | return &Device{ 133 | Hostname: resolve.Hostname(ipAddr), 134 | LocalIP: ipAddr, 135 | Kind: DeviceKindRouter, 136 | Up: true, 137 | }, nil 138 | } 139 | 140 | func getCIDR(_ context.Context) (string, error) { 141 | localIP, err := getCurrentDeviceLocalIP() 142 | if err != nil { 143 | return "", fmt.Errorf("failed to get local ip: %w", err) 144 | } 145 | return fmt.Sprintf("%s/24", localIP.Mask(localIP.DefaultMask())), nil 146 | } 147 | 148 | func getHosts(_ context.Context, cidr string, router *Device) ([]string, error) { 149 | ip, network, err := net.ParseCIDR(cidr) 150 | if err != nil { 151 | return nil, fmt.Errorf("failed to parse cidr %s: %w", cidr, err) 152 | } 153 | 154 | inc := func(ip net.IP) { 155 | for j := len(ip) - 1; j >= 0; j-- { 156 | ip[j]++ 157 | if ip[j] > 0 { 158 | break 159 | } 160 | } 161 | } 162 | 163 | var ips []string 164 | for ip := ip.Mask(network.Mask); network.Contains(ip); inc(ip) { 165 | if ip.String() == router.LocalIP.String() { 166 | continue 167 | } 168 | ips = append(ips, ip.String()) 169 | } 170 | return ips[1 : len(ips)-1], nil 171 | } 172 | 173 | func getCurrentDeviceLocalIP() (net.IP, error) { 174 | c, err := net.Dial("udp", "8.8.8.8:80") 175 | if err != nil { 176 | return nil, fmt.Errorf("failed to dial google dns : %w", err) 177 | } 178 | defer c.Close() 179 | 180 | localAddr, ok := c.LocalAddr().(*net.UDPAddr) 181 | if !ok { 182 | return nil, errors.New("failed to resolve local IP") 183 | } 184 | return localAddr.IP, nil 185 | } 186 | 187 | func getCurrentDeviceRemoteIP() (net.IP, error) { 188 | r, err := http.Get("http://myexternalip.com/raw") 189 | if err != nil { 190 | return nil, err 191 | } 192 | defer r.Body.Close() 193 | 194 | b, err := io.ReadAll(r.Body) 195 | if err != nil { 196 | return nil, err 197 | } 198 | 199 | var remoteIP net.IP 200 | ipAddr := string(b) 201 | if strings.Contains(ipAddr, ":") { 202 | remoteIP = net.ParseIP(ipAddr).To16() 203 | } else { 204 | remoteIP = net.ParseIP(ipAddr).To4() 205 | } 206 | if remoteIP == nil { 207 | return nil, fmt.Errorf("failed to get resolve ip %q as ipv4", b) 208 | } 209 | return remoteIP, nil 210 | } 211 | 212 | func dedupe(hosts []string) []string { 213 | m := make(map[string]int) 214 | var filteredHosts []string 215 | for _, host := range hosts { 216 | if m[host] == 0 { 217 | m[host]++ 218 | filteredHosts = append(filteredHosts, host) 219 | continue 220 | } 221 | } 222 | return filteredHosts 223 | } 224 | 225 | func removeIP(ip string, hosts []string) []string { 226 | var filteredHosts []string 227 | for _, host := range hosts { 228 | if host == ip { 229 | continue 230 | } 231 | filteredHosts = append(filteredHosts, host) 232 | } 233 | return filteredHosts 234 | } 235 | 236 | func ping(ip string) bool { 237 | p := goping.NewPinger() 238 | p.Network("udp") 239 | 240 | netProto := icmpIpv4 241 | if strings.Contains(ip, ":") { 242 | netProto = icmpIpv6 243 | } 244 | 245 | addr, err := net.ResolveIPAddr(netProto, ip) 246 | if err != nil { 247 | return false 248 | } 249 | 250 | p.AddIPAddr(addr) 251 | p.MaxRTT = time.Second 252 | 253 | var up bool 254 | p.OnRecv = func(addr *net.IPAddr, t time.Duration) { 255 | up = true 256 | } 257 | p.Run() 258 | return up 259 | } 260 | -------------------------------------------------------------------------------- /internal/list/list_test.go: -------------------------------------------------------------------------------- 1 | package list 2 | 3 | import ( 4 | "context" 5 | "testing" 6 | 7 | "github.com/stretchr/testify/require" 8 | ) 9 | 10 | func TestListDevices(t *testing.T) { 11 | t.Parallel() 12 | t.Run("ShouldPass", func(t *testing.T) { 13 | // We only check the current device exists in the list of devices 14 | // because its the only device guaranteed to be on the LAN. 15 | // Asserting against a static list of devices is not reliable because those 16 | // devices may not be on the network at anymore at any given time. 17 | t.Run("find current device in list of devices", func(t *testing.T) { 18 | t.Parallel() 19 | ctx := context.Background() 20 | currentDevice, err := getCurrentDevice(ctx) 21 | require.NoError(t, err) 22 | devices, err := Devices(ctx) 23 | require.NoError(t, err) 24 | var foundDevice bool 25 | for _, d := range devices { 26 | if d.LocalIP.String() == currentDevice.LocalIP.String() { 27 | foundDevice = true 28 | } 29 | } 30 | require.True(t, foundDevice) 31 | }) 32 | }) 33 | t.Run("ShouldFail", func(t *testing.T) { 34 | t.Run("get device using invalid ip", func(t *testing.T) { 35 | d, err := getDevice(context.Background(), "invalid") 36 | require.Nil(t, d) 37 | require.Error(t, err) 38 | }) 39 | t.Run("get hosts using invalid CIDR", func(t *testing.T) { 40 | hosts, err := getHosts(context.Background(), "invalid", nil) 41 | require.Nil(t, hosts) 42 | require.Error(t, err) 43 | }) 44 | }) 45 | } 46 | -------------------------------------------------------------------------------- /internal/resolve/lookup.go: -------------------------------------------------------------------------------- 1 | package resolve 2 | 3 | import ( 4 | "fmt" 5 | "net" 6 | "strings" 7 | "time" 8 | 9 | "github.com/ammario/ipisp" 10 | ) 11 | 12 | // Record can be used as a common type between lookup commands 13 | // that supports json and table output. 14 | type Record struct { 15 | Hostname string `json:"hostname" yaml:"hostname" table:"HOSTNAME"` 16 | IP net.IP `json:"ip" yaml:"ip" table:"IP_ADDRESS"` 17 | } 18 | 19 | type NetworkRecord struct { 20 | Hostname string `json:"hostname" yaml:"hostname,flow" table:"HOSTNAME"` 21 | NetworkIP net.IP `json:"network" yaml:"network" table:"NETWORK"` 22 | } 23 | 24 | // InternetServiceProvider describes an internet service provider. 25 | type InternetServiceProvider struct { 26 | Name string `json:"name" table:"NAME"` 27 | IP *net.IP `json:"ip_address" table:"IP"` 28 | Country string `json:"country" table:"COUNTRY"` 29 | Registry string `json:"registry" table:"REGISTRY"` 30 | IpRange *net.IPNet `json:"ip_range" table:"IP_RANGE"` 31 | AutonomousServiceNumber string `json:"autonomous_service_number" table:"ASN"` 32 | AllocatedAt *time.Time `json:"allocated_at" table:"ALLOCATED_AT"` 33 | } 34 | 35 | // NameServer is used in place of the standard library object to support table writes. 36 | type NameServer struct { 37 | IP net.IP `json:"ip" table:"IP"` 38 | Host string `json:"nameserver" table:"Nameserver"` 39 | } 40 | 41 | const notAvailable = "N/A" 42 | 43 | func Hostname(ip net.IP) string { 44 | record := HostNameByIP(ip) 45 | if record.Hostname == "" { 46 | return notAvailable 47 | } 48 | return record.Hostname 49 | } 50 | 51 | // HostNameByIP returns the hostname for the provided ip address. 52 | func HostNameByIP(ip net.IP) *Record { 53 | var hostname string 54 | hostnames := HostNamesByIP(ip) 55 | if len(hostnames) > 0 { 56 | hostname = hostnames[0] 57 | } 58 | return &Record{ 59 | IP: ip, 60 | Hostname: hostname, 61 | } 62 | } 63 | 64 | // HostNamesByIP returns all hostnames found for the provided ip address. 65 | func HostNamesByIP(ip net.IP) []string { 66 | hostnames, _ := net.LookupAddr(ip.String()) 67 | return hostnames 68 | } 69 | 70 | // AddrByHostName resolves the ip address of the provided hostname. 71 | func AddrByHostName(hostname string) (*Record, error) { 72 | ipAddrs, err := AddrsByHostName(hostname) 73 | if err != nil { 74 | return nil, err 75 | } 76 | 77 | if len(ipAddrs) == 0 { 78 | return nil, fmt.Errorf("no addresses found for hostname %q", hostname) 79 | } 80 | 81 | var ipAddr net.IP 82 | if strings.Contains(string(*ipAddrs[0]), ":") { 83 | ipAddr = ipAddrs[0].To16() 84 | } else { 85 | ipAddr = ipAddrs[0].To4() 86 | } 87 | 88 | return &Record{ 89 | Hostname: hostname, 90 | IP: ipAddr, 91 | }, err 92 | } 93 | 94 | // AddrsByHostName returns all ip addresses found for the provided hostname. 95 | func AddrsByHostName(hostname string) ([]*net.IP, error) { 96 | addrs, err := net.LookupHost(hostname) 97 | if err != nil { 98 | return nil, fmt.Errorf("failed to look up ip addresses for hostname %q: %v", hostname, err) 99 | } 100 | 101 | if len(addrs) == 0 { 102 | return nil, fmt.Errorf("no ip addresses found for hostname %q", hostname) 103 | } 104 | 105 | var ipAddrs []*net.IP 106 | 107 | for _, a := range addrs { 108 | ipAddr := net.ParseIP(a).To4() 109 | if ipAddr == nil { 110 | continue 111 | } 112 | ipAddrs = append(ipAddrs, &ipAddr) 113 | } 114 | return ipAddrs, nil 115 | } 116 | 117 | // NameServersByHostName looks up all nameservers for the provided hostname. 118 | func NameServersByHostName(hostname string) ([]NameServer, error) { 119 | internalNameServers, err := net.LookupNS(stripHostname(hostname)) 120 | if err != nil { 121 | return nil, fmt.Errorf("failed to look up name server for hostname %q : %v", hostname, err) 122 | } 123 | if len(internalNameServers) == 0 { 124 | return nil, fmt.Errorf("no name servers found for hostname %q", hostname) 125 | } 126 | var nameServers []NameServer 127 | for _, ns := range internalNameServers { 128 | record, err := AddrByHostName(ns.Host) 129 | if err != nil { 130 | return nil, fmt.Errorf("failed to get ip by hostname %q: %w", ns.Host, err) 131 | } 132 | nameServers = append(nameServers, 133 | NameServer{ 134 | IP: record.IP.To4(), 135 | Host: ns.Host, 136 | }, 137 | ) 138 | } 139 | return nameServers, nil 140 | } 141 | 142 | // NetworkByHost returns the network address for the provided hostname. 143 | func NetworkByHost(host string) (*NetworkRecord, error) { 144 | var hostname string 145 | ipAddr := net.ParseIP(host) 146 | if ipAddr == nil { 147 | hostname = host 148 | record, err := AddrByHostName(host) 149 | if err != nil { 150 | return nil, fmt.Errorf("%q is an invalild host: %v", host, err) 151 | } 152 | ipAddr = record.IP 153 | } else { 154 | hostname = Hostname(ipAddr) 155 | } 156 | 157 | network := ipAddr.Mask(ipAddr.DefaultMask()) 158 | if network == nil { 159 | return nil, fmt.Errorf("failed to get network address of host %q", ipAddr.String()) 160 | } 161 | 162 | return &NetworkRecord{ 163 | Hostname: hostname, 164 | NetworkIP: network, 165 | }, nil 166 | } 167 | 168 | // HostAndAddr returns the hostname and ip address of host whether host is an IP address or a hostname. 169 | // HostAndAddr returns a non-nil error if host is an invalid ip address or a hostname that cannot be resolved to an IP address. 170 | func HostAndAddr(host string) (string, *net.IP, error) { 171 | var hostname string 172 | 173 | ip := net.ParseIP(host) 174 | if ip == nil { 175 | hostname = host 176 | record, err := AddrByHostName(hostname) 177 | if err != nil { 178 | return "", nil, fmt.Errorf("failed to get ip address by hostname %q: %w", hostname, err) 179 | } 180 | ip = record.IP 181 | } else { 182 | hostname = Hostname(ip) 183 | } 184 | return hostname, &ip, nil 185 | } 186 | 187 | // ServiceProvider returns the internet service provider information for ip. 188 | func ServiceProvider(ip *net.IP) (*InternetServiceProvider, error) { 189 | client, err := ipisp.NewDNSClient() 190 | if err != nil { 191 | return nil, fmt.Errorf("failed to initialize new dns client: %w", err) 192 | } 193 | defer client.Close() 194 | 195 | resp, err := client.LookupIP(*ip) 196 | if err != nil { 197 | return nil, err 198 | } 199 | 200 | return &InternetServiceProvider{ 201 | Name: resp.Name.Raw, 202 | IP: &resp.IP, 203 | Country: resp.Country, 204 | Registry: resp.Registry, 205 | IpRange: resp.Range, 206 | AutonomousServiceNumber: resp.ASN.String(), 207 | AllocatedAt: &resp.AllocatedAt, 208 | }, nil 209 | } 210 | 211 | func stripHostname(hostname string) string { 212 | hostname = strings.ReplaceAll(hostname, "https://", "") 213 | hostname = strings.ReplaceAll(hostname, "http://", "") 214 | hostname = strings.ReplaceAll(hostname, "www.", "") 215 | return hostname 216 | } 217 | -------------------------------------------------------------------------------- /internal/resolve/lookup_test.go: -------------------------------------------------------------------------------- 1 | package resolve 2 | 3 | import ( 4 | "net" 5 | "testing" 6 | "time" 7 | 8 | "github.com/stretchr/testify/require" 9 | ) 10 | 11 | func TestLookup(t *testing.T) { 12 | t.Parallel() 13 | googleDNS := net.ParseIP("8.8.8.8") 14 | t.Run("ShouldPass", func(t *testing.T) { 15 | t.Parallel() 16 | t.Run("hostname by ip", func(t *testing.T) { 17 | t.Parallel() 18 | record := HostNameByIP(googleDNS) 19 | require.Equal(t, "dns.google.", record.Hostname) 20 | }) 21 | t.Run("hostnames by ip", func(t *testing.T) { 22 | t.Parallel() 23 | hostnames := HostNamesByIP(googleDNS) 24 | require.Len(t, hostnames, 1) 25 | }) 26 | t.Run("nameservers by hostname", func(t *testing.T) { 27 | t.Parallel() 28 | nameservers, err := NameServersByHostName("farishuskovic.dev") 29 | require.NoError(t, err) 30 | require.Len(t, nameservers, 4) 31 | }) 32 | t.Run("network by hostname", func(t *testing.T) { 33 | t.Parallel() 34 | expected := net.ParseIP("8.0.0.0") 35 | record, err := NetworkByHost(googleDNS.String()) 36 | require.NoError(t, err) 37 | require.Equal(t, expected.String(), record.NetworkIP.String()) 38 | }) 39 | t.Run("hostname and ip address using hostname", func(t *testing.T) { 40 | t.Parallel() 41 | expected, err := AddrByHostName("dns.google.") 42 | require.NoError(t, err) 43 | host, got, err := HostAndAddr("dns.google.") 44 | require.NoError(t, err) 45 | require.Equal(t, "dns.google.", host) 46 | require.Equal(t, expected.IP.String(), got.String()) 47 | }) 48 | t.Run("hostname and ip address using ip", func(t *testing.T) { 49 | t.Parallel() 50 | expected, err := AddrByHostName(googleDNS.String()) 51 | require.NoError(t, err) 52 | host, got, err := HostAndAddr(googleDNS.String()) 53 | require.NoError(t, err) 54 | require.Equal(t, host, "dns.google.") 55 | require.Equal(t, expected.IP.String(), got.String()) 56 | }) 57 | t.Run("internet service provider", func(t *testing.T) { 58 | t.Parallel() 59 | dec1st1992 := time.Date(1992, time.December, 1, 0, 0, 0, 0, time.UTC) 60 | _, network, err := net.ParseCIDR("8.8.8.0/24") 61 | require.NoError(t, err) 62 | expected := &InternetServiceProvider{ 63 | Name: "GOOGLE, US", 64 | IP: &googleDNS, 65 | Country: "US", 66 | Registry: "ARIN", 67 | IpRange: network, 68 | AutonomousServiceNumber: "AS15169", 69 | AllocatedAt: &dec1st1992, 70 | } 71 | isp, err := ServiceProvider(&googleDNS) 72 | require.NoError(t, err) 73 | require.Equal(t, expected, isp) 74 | }) 75 | }) 76 | t.Run("ShouldFail", func(t *testing.T) { 77 | t.Parallel() 78 | t.Run("hostname by ip if invalid ip is input", func(t *testing.T) { 79 | t.Parallel() 80 | record := HostNameByIP(net.IP("invalid")) 81 | require.Empty(t, record.Hostname) 82 | }) 83 | t.Run("hostnames by ip if invalid ip is input", func(t *testing.T) { 84 | t.Parallel() 85 | hostnames := HostNamesByIP(net.IP("invalid")) 86 | require.Nil(t, hostnames) 87 | }) 88 | t.Run("addr by hostname if hostname is invalid", func(t *testing.T) { 89 | t.Parallel() 90 | addrs, err := AddrByHostName("invalid") 91 | require.Nil(t, addrs) 92 | require.Error(t, err) 93 | }) 94 | t.Run("addr by hostname if hostname is invalid", func(t *testing.T) { 95 | t.Parallel() 96 | addrs, err := AddrByHostName("invalid") 97 | require.Nil(t, addrs) 98 | require.Error(t, err) 99 | }) 100 | }) 101 | } 102 | -------------------------------------------------------------------------------- /internal/resolve/private.go: -------------------------------------------------------------------------------- 1 | package resolve 2 | 3 | import ( 4 | "fmt" 5 | "net" 6 | ) 7 | 8 | // IsPrivate checks whether or not ip is a private ip. 9 | func IsPrivate(ip *net.IP) bool { 10 | var privateIPBlocks []*net.IPNet 11 | for _, cidr := range []string{ 12 | "127.0.0.0/8", // IPv4 loopback 13 | "10.0.0.0/8", // RFC1918 14 | "172.16.0.0/12", // RFC1918 15 | "192.168.0.0/16", // RFC1918 16 | "169.254.0.0/16", // RFC3927 link-local 17 | "::1/128", // IPv6 loopback 18 | "fe80::/10", // IPv6 link-local 19 | "fc00::/7", // IPv6 unique local addr 20 | } { 21 | _, block, err := net.ParseCIDR(cidr) 22 | if err != nil { 23 | panic(fmt.Errorf("parse error on %q: %v", cidr, err)) 24 | } 25 | privateIPBlocks = append(privateIPBlocks, block) 26 | } 27 | 28 | if ip.IsLoopback() || ip.IsLinkLocalUnicast() || ip.IsLinkLocalMulticast() { 29 | return true 30 | } 31 | 32 | for _, block := range privateIPBlocks { 33 | if block.Contains(*ip) { 34 | return true 35 | } 36 | } 37 | return false 38 | } 39 | -------------------------------------------------------------------------------- /internal/resolve/private_test.go: -------------------------------------------------------------------------------- 1 | package resolve 2 | 3 | import ( 4 | "net" 5 | "testing" 6 | 7 | "github.com/stretchr/testify/require" 8 | ) 9 | 10 | func TestPrivate(t *testing.T) { 11 | t.Parallel() 12 | for _, test := range []struct { 13 | name string 14 | ip net.IP 15 | shouldBePrivate bool 16 | }{ 17 | { 18 | name: "loopbackIpV4", 19 | ip: net.ParseIP("127.0.0.1"), 20 | shouldBePrivate: true, 21 | }, 22 | { 23 | name: "loopbackIpV6", 24 | ip: net.ParseIP("::1"), 25 | shouldBePrivate: true, 26 | }, 27 | { 28 | name: "private class A", 29 | ip: net.ParseIP("192.168.0.1"), 30 | shouldBePrivate: true, 31 | }, 32 | { 33 | name: "private class B", 34 | ip: net.ParseIP("172.16.0.1"), 35 | shouldBePrivate: true, 36 | }, 37 | { 38 | name: "private class C", 39 | ip: net.ParseIP("192.168.0.1"), 40 | shouldBePrivate: true, 41 | }, 42 | { 43 | name: "google DNS", 44 | ip: net.ParseIP("8.8.8.8"), 45 | shouldBePrivate: false, 46 | }, 47 | } { 48 | t.Run(test.name, func(t *testing.T) { 49 | t.Parallel() 50 | require.Equal(t, test.shouldBePrivate, IsPrivate(&test.ip)) 51 | }) 52 | } 53 | } 54 | -------------------------------------------------------------------------------- /internal/scanner/scanner.go: -------------------------------------------------------------------------------- 1 | package scanner 2 | 3 | import ( 4 | "context" 5 | "fmt" 6 | "net" 7 | "strconv" 8 | "strings" 9 | "sync" 10 | "time" 11 | 12 | goping "github.com/tatsushid/go-fastping" 13 | 14 | "github.com/fuskovic/networker/v3/internal/resolve" 15 | ) 16 | 17 | var ( 18 | wellKnownPorts = 1024 19 | allPorts = 65535 20 | ) 21 | 22 | type Scan struct { 23 | IP string `json:"ip" table:"IP"` 24 | Host string `json:"hostname" table:"HOSTNAME"` 25 | Ports []int `json:"open_ports" table:"OPEN_PORTS"` 26 | Up bool `json:"up" yaml:"up" table:"UP"` 27 | } 28 | 29 | type Scanner interface { 30 | Scan(context.Context) ([]Scan, error) 31 | } 32 | 33 | type scanner struct { 34 | sync.Mutex 35 | scans []Scan 36 | shouldScanAll bool 37 | } 38 | 39 | // NewScanner initializes a new port-scanner based on whether or not the user wants to scan all ports or just the well-known ports. 40 | func New(hosts []string, shouldScanAll bool) Scanner { 41 | var ( 42 | scans []Scan 43 | wg sync.WaitGroup 44 | mu sync.Mutex 45 | ) 46 | 47 | for _, host := range hosts { 48 | wg.Add(1) 49 | go func(ip string) { 50 | defer wg.Done() 51 | p := goping.NewPinger() 52 | _, _ = p.Network("udp") 53 | 54 | netProto := "ip4:icmp" 55 | if strings.Index(ip, ":") != -1 { 56 | netProto = "ip6:ipv6-icmp" 57 | } 58 | 59 | addr, err := net.ResolveIPAddr(netProto, ip) 60 | if err != nil { 61 | return 62 | } 63 | 64 | p.AddIPAddr(addr) 65 | p.MaxRTT = time.Second 66 | 67 | s := Scan{IP: ip} 68 | p.OnRecv = func(addr *net.IPAddr, t time.Duration) { s.Up = true } 69 | if err := p.Run(); err != nil { 70 | return 71 | } 72 | 73 | mu.Lock() 74 | scans = append(scans, s) 75 | mu.Unlock() 76 | }(host) 77 | } 78 | wg.Wait() 79 | 80 | return &scanner{ 81 | Mutex: sync.Mutex{}, 82 | scans: scans, 83 | shouldScanAll: shouldScanAll, 84 | } 85 | } 86 | 87 | func (s *scanner) Scan(ctx context.Context) ([]Scan, error) { 88 | var wg sync.WaitGroup 89 | for _, scan := range s.scans { 90 | if scan.Up { 91 | wg.Add(1) 92 | go func(ip string) { 93 | defer wg.Done() 94 | s.scanHost(ip) 95 | }(scan.IP) 96 | } 97 | } 98 | wg.Wait() 99 | 100 | for i := range s.scans { 101 | hostname, _, err := resolve.HostAndAddr(s.scans[i].IP) 102 | if err != nil { 103 | return nil, fmt.Errorf("failed to lookup hostname by ip for %s: %w", s.scans[i].IP, err) 104 | } 105 | s.scans[i].Host = hostname 106 | } 107 | return s.scans, nil 108 | } 109 | 110 | func (s *scanner) scanHost(host string) { 111 | var wg sync.WaitGroup 112 | for _, port := range portsToScan(s.shouldScanAll) { 113 | wg.Add(1) 114 | go func(p int) { 115 | defer wg.Done() 116 | if isOpen(host, p) { 117 | s.add(host, p) 118 | } 119 | }(port) 120 | } 121 | wg.Wait() 122 | } 123 | 124 | func (s *scanner) add(ip string, port int) { 125 | s.Lock() 126 | for i := range s.scans { 127 | if s.scans[i].IP == ip { 128 | s.scans[i].Ports = append(s.scans[i].Ports, port) 129 | } 130 | } 131 | s.Unlock() 132 | } 133 | 134 | func isOpen(ip string, port int) bool { 135 | addr := net.JoinHostPort(ip, strconv.Itoa(port)) 136 | conn, err := net.DialTimeout("tcp", addr, 5*time.Second) 137 | if err != nil { 138 | return false 139 | } 140 | defer conn.Close() 141 | return true 142 | } 143 | 144 | func portsToScan(shouldScanAll bool) []int { 145 | var max int 146 | if shouldScanAll { 147 | max = allPorts 148 | } else { 149 | max = wellKnownPorts 150 | } 151 | 152 | var ports []int 153 | for p := 0; p < max; p++ { 154 | ports = append(ports, p) 155 | } 156 | return ports 157 | } 158 | -------------------------------------------------------------------------------- /internal/scanner/scanner_test.go: -------------------------------------------------------------------------------- 1 | package scanner 2 | 3 | import ( 4 | "context" 5 | "net" 6 | "strconv" 7 | "testing" 8 | 9 | "github.com/stretchr/testify/require" 10 | ) 11 | 12 | func TestScanner(t *testing.T) { 13 | t.Skip("flakey") 14 | // start a listener on any available local port 15 | l, err := net.Listen("tcp", "127.0.0.1:0") 16 | require.NoError(t, err) 17 | defer l.Close() 18 | 19 | // check which port the listener is running to determine how many ports we need to scan 20 | host, portStr, err := net.SplitHostPort(l.Addr().String()) 21 | require.NoError(t, err) 22 | port, err := strconv.Atoi(portStr) 23 | require.NoError(t, err) 24 | var shouldScanAll bool 25 | if port > wellKnownPorts { 26 | shouldScanAll = true 27 | } 28 | 29 | // initialize a new scanner and scan localhost 30 | hostsToScan := []string{host} 31 | results, err := New(hostsToScan, shouldScanAll).Scan(context.Background()) 32 | require.NoError(t, err) 33 | require.Equal(t, 1, len(results)) 34 | 35 | // assert that the port the listener was started on is listed as an open port in the results 36 | var foundPort bool 37 | for _, openPort := range results[0].Ports { 38 | if openPort == port { 39 | foundPort = true 40 | } 41 | } 42 | require.True(t, foundPort) 43 | } 44 | -------------------------------------------------------------------------------- /internal/shell/dialer.go: -------------------------------------------------------------------------------- 1 | package shell 2 | 3 | import ( 4 | "errors" 5 | "fmt" 6 | "io" 7 | "log" 8 | "net" 9 | "os" 10 | "syscall" 11 | 12 | "golang.org/x/crypto/ssh/terminal" 13 | ) 14 | 15 | // Dial connects to the shell that it expects to be served at addr. 16 | func Dial(addr string) error { 17 | conn, err := net.Dial("tcp", addr) 18 | if err != nil { 19 | return fmt.Errorf("failed to dial %q : %w", addr, err) 20 | } 21 | defer conn.Close() 22 | 23 | oldState, err := terminal.MakeRaw(int(os.Stdin.Fd())) 24 | if err != nil { 25 | log.Printf("failed to get previous state of terminal: %s", err) 26 | } 27 | 28 | defer func() { 29 | if oldState != nil { 30 | _ = terminal.Restore(int(os.Stdin.Fd()), oldState) 31 | } 32 | }() 33 | 34 | errChan := make(chan error, 1) 35 | 36 | go func() { 37 | if _, err := io.Copy(os.Stdout, conn); err != nil && !errors.Is(err, net.ErrClosed) { 38 | errChan <- fmt.Errorf("failed to read output from connection: %s\n", err) 39 | return 40 | } 41 | errChan <- nil 42 | }() 43 | 44 | go func() { 45 | if _, err = io.Copy(conn, os.Stdin); err != nil && !errors.Is(err, syscall.EPIPE) { 46 | errChan <- fmt.Errorf("failed to write input to connection: %w", err) 47 | return 48 | } 49 | errChan <- nil 50 | }() 51 | 52 | return <-errChan 53 | } 54 | -------------------------------------------------------------------------------- /internal/shell/dialer_test.go: -------------------------------------------------------------------------------- 1 | package shell 2 | 3 | import ( 4 | "os/exec" 5 | "strconv" 6 | "strings" 7 | "testing" 8 | "time" 9 | 10 | "github.com/stretchr/testify/require" 11 | ) 12 | 13 | func TestDialer(t *testing.T) { 14 | t.Run("ShouldFail", func(t *testing.T) { 15 | t.Run("if addr is not serving shell", func(t *testing.T) { 16 | require.Error(t, Dial("localhost:80")) 17 | }) 18 | }) 19 | t.Run("ShouldPass", func(t *testing.T) { 20 | // get the process id of the current shell 21 | getShellPid := exec.Command("bash", "-c", "echo $$") 22 | output, err := getShellPid.CombinedOutput() 23 | require.NoError(t, err) 24 | out := strings.TrimSpace(string(output)) 25 | ogPid, err := strconv.Atoi(out) 26 | require.NoError(t, err) 27 | 28 | go func() { 29 | // start the server 30 | require.NoError(t, Serve("bash", 4444)) 31 | }() 32 | 33 | // Connect to it 34 | go func() { 35 | require.NoError(t, Dial("localhost:4444")) 36 | }() 37 | 38 | // grace period to wait for connection to establish 39 | time.Sleep(time.Second) 40 | 41 | // get the process id of the new shell 42 | getShellPid = exec.Command("bash", "-c", "echo $$") 43 | output, err = getShellPid.CombinedOutput() 44 | require.NoError(t, err) 45 | out = strings.TrimSpace(string(output)) 46 | newPid, err := strconv.Atoi(out) 47 | require.NoError(t, err) 48 | 49 | // assert that the current shells process id is different than the original 50 | require.NotEqual(t, ogPid, newPid) 51 | }) 52 | } 53 | -------------------------------------------------------------------------------- /internal/shell/server.go: -------------------------------------------------------------------------------- 1 | package shell 2 | 3 | import ( 4 | "errors" 5 | "fmt" 6 | "io" 7 | "log" 8 | "net" 9 | "os" 10 | "os/exec" 11 | "os/signal" 12 | "time" 13 | 14 | "github.com/creack/pty" 15 | ) 16 | 17 | // Serve serves a shell on the designated port. 18 | func Serve(shell string, port int) error { 19 | if !isSupportedShell(shell) { 20 | return fmt.Errorf("shell %q is not supported", shell) 21 | } 22 | 23 | if _, err := exec.LookPath(shell); err != nil { 24 | return fmt.Errorf("shell %q does not exist on system: %w", shell, err) 25 | } 26 | 27 | if !isValidPort(port) { 28 | return fmt.Errorf("%d is not a valid port", port) 29 | } 30 | 31 | sigChan := make(chan os.Signal, 1) 32 | signal.Notify(sigChan, os.Interrupt) 33 | errChan := make(chan error, 1) 34 | 35 | go func() { 36 | <-sigChan 37 | println() 38 | log.Println("received interrupt signal") 39 | log.Println("shutting down") 40 | errChan <- nil 41 | }() 42 | 43 | l, err := net.Listen("tcp", fmt.Sprintf("localhost:%d", port)) 44 | if err != nil { 45 | return fmt.Errorf("failed to listen on port %d: %w", port, err) 46 | } 47 | defer l.Close() 48 | 49 | go func() { 50 | for { 51 | proc, err := pty.Start(exec.Command(shell)) 52 | if err != nil { 53 | errChan <- fmt.Errorf("failed to start new shell process: %w", err) 54 | return 55 | } 56 | defer proc.Close() 57 | 58 | log.Printf("serving a new %s process on localhost:%d\n", shell, port) 59 | 60 | conn, err := l.Accept() 61 | if err != nil { 62 | errChan <- fmt.Errorf("failed to accept incoming connection: %w", err) 63 | return 64 | } 65 | defer conn.Close() 66 | 67 | go handleConnection(conn, proc) 68 | } 69 | }() 70 | return <-errChan 71 | } 72 | 73 | func handleConnection(conn net.Conn, proc *os.File) { 74 | defer func() { 75 | if err := conn.Close(); err != nil { 76 | log.Printf("failed to close connection for %s: %s\n", conn.RemoteAddr(), err) 77 | } 78 | 79 | if err := proc.Close(); err != nil { 80 | log.Printf("failed to kill process started by %s: %s\n", conn.RemoteAddr(), err) 81 | } 82 | }() 83 | 84 | connectedAt := time.Now().UTC() 85 | log.Printf("client %s connected at: %s\n", conn.RemoteAddr(), connectedAt) 86 | 87 | go func() { 88 | if _, err := io.Copy(proc, conn); err != nil && !errors.Is(err, net.ErrClosed) { 89 | log.Printf("failed to read from client connection: %+v\n", err) 90 | } 91 | }() 92 | 93 | if _, err := io.Copy(conn, proc); err != nil { 94 | log.Printf("failed to write output to connection: %s", err) 95 | } 96 | 97 | log.Printf("client %s disconnected after %s\n", conn.RemoteAddr(), time.Since(connectedAt)) 98 | } 99 | 100 | func isSupportedShell(targetShell string) bool { 101 | for _, sh := range []string{"bash", "zsh", "sh", "fish"} { 102 | if sh == targetShell { 103 | return true 104 | } 105 | } 106 | return false 107 | } 108 | 109 | func isValidPort(port int) bool { 110 | return port > -1 && port < 65536 111 | } 112 | -------------------------------------------------------------------------------- /internal/shell/server_test.go: -------------------------------------------------------------------------------- 1 | package shell 2 | 3 | import ( 4 | "errors" 5 | "net" 6 | "testing" 7 | "time" 8 | 9 | "github.com/stretchr/testify/require" 10 | ) 11 | 12 | func TestServer(t *testing.T) { 13 | t.Run("ShouldFail", func(t *testing.T) { 14 | t.Run("if shell is unsupported", func(t *testing.T) { 15 | expected := errors.New("shell \"unsupported\" is not supported") 16 | got := Serve("unsupported", 80) 17 | require.Error(t, got) 18 | require.Equal(t, expected, got) 19 | }) 20 | t.Run("if shell is not installed", func(t *testing.T) { 21 | expected := "shell \"fish\" does not exist on system: exec: \"fish\": executable file not found in $PATH" 22 | got := Serve("fish", 80) 23 | require.Error(t, got) 24 | require.Equal(t, expected, got.Error()) 25 | }) 26 | t.Run("if port is negative number", func(t *testing.T) { 27 | expected := "-1 is not a valid port" 28 | got := Serve("bash", -1) 29 | require.Error(t, got) 30 | require.Equal(t, expected, got.Error()) 31 | }) 32 | t.Run("if port is invalid", func(t *testing.T) { 33 | expected := "70000 is not a valid port" 34 | got := Serve("bash", 70000) 35 | require.Error(t, got) 36 | require.Equal(t, expected, got.Error()) 37 | }) 38 | }) 39 | t.Run("ShouldPass", func(t *testing.T) { 40 | go func() { 41 | // start the server 42 | require.NoError(t, Serve("bash", 1111)) 43 | }() 44 | 45 | // validate that its up 46 | conn, err := net.DialTimeout("tcp", "localhost:1111", 3*time.Second) 47 | require.NoError(t, err) 48 | 49 | // close the client connection 50 | require.NoError(t, conn.Close()) 51 | }) 52 | } 53 | -------------------------------------------------------------------------------- /internal/spinner/spinner.go: -------------------------------------------------------------------------------- 1 | package spinner 2 | 3 | import ( 4 | "time" 5 | 6 | "github.com/briandowns/spinner" 7 | ) 8 | 9 | var s = spinner.New(spinner.CharSets[36], 50*time.Millisecond) 10 | 11 | func Start() { s.Start() } 12 | func Stop() { s.Stop() } 13 | -------------------------------------------------------------------------------- /internal/test/hooks.go: -------------------------------------------------------------------------------- 1 | package test 2 | 3 | import ( 4 | "os/exec" 5 | "testing" 6 | 7 | "github.com/stretchr/testify/require" 8 | ) 9 | 10 | // WithNetworker is a pre-test hook that asserts the networker binary is globally installed before running the test. 11 | // It's intended to be used in the cmd/networker pkg. 12 | func WithNetworker(t *testing.T, name string, fn func(t *testing.T)) { 13 | t.Helper() 14 | t.Run(name, func(t *testing.T) { 15 | // make sure networker is installed 16 | cmd := exec.Command("which", "networker") 17 | require.NoError(t, cmd.Run(), "networker not installed") 18 | fn(t) 19 | }) 20 | } 21 | -------------------------------------------------------------------------------- /internal/test/root.go: -------------------------------------------------------------------------------- 1 | package test 2 | 3 | import ( 4 | "os/exec" 5 | "strings" 6 | "testing" 7 | 8 | "github.com/stretchr/testify/require" 9 | ) 10 | 11 | // ProjectRoot is a utility function for returning root path of the networker source code on this machine. 12 | // It's primary purpose is to help construct absolute paths needed by tests. 13 | func ProjectRoot(t *testing.T) string { 14 | t.Helper() 15 | output, err := exec.Command("git", "rev-parse", "--show-toplevel").CombinedOutput() 16 | require.NoError(t, err) 17 | return strings.Replace(string(output), "\n", "", 1) 18 | } 19 | -------------------------------------------------------------------------------- /internal/usage/fatal.go: -------------------------------------------------------------------------------- 1 | package usage 2 | 3 | import ( 4 | "log" 5 | "os" 6 | 7 | "github.com/spf13/cobra" 8 | ) 9 | 10 | // Fatal prints the usage for the flagset and the args before returning an exit code 1. 11 | func Fatal(cmd *cobra.Command, args ...any) { 12 | log.Print(args...) 13 | _ = cmd.Usage() 14 | os.Exit(1) 15 | } 16 | 17 | // Fatalf prints the usage for the flagset and the formatted args before returning an exit code 1. 18 | func Fatalf(cmd *cobra.Command, format string, args ...any) { 19 | log.Printf(format, args...) 20 | _ = cmd.Usage() 21 | os.Exit(1) 22 | } 23 | -------------------------------------------------------------------------------- /main.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import "github.com/fuskovic/networker/v3/cmd" 4 | 5 | func main() { 6 | cmd.Root.CompletionOptions.DisableDefaultCmd = true 7 | cmd.Root.Execute() 8 | } 9 | -------------------------------------------------------------------------------- /scripts/build.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | PROJECT_ROOT=$(git rev-parse --show-toplevel) 4 | rm -rf $PROJECT_ROOT/bin > /dev/null 5 | 6 | echo "compiling for OSX" 7 | go build -o $PROJECT_ROOT/bin/networker_darwin $PROJECT_ROOT/main.go 8 | if [ $? -ne 0 ]; then 9 | echo "failed to compile networker for OSX" && exit 1 10 | fi 11 | 12 | echo "compiling for linux" 13 | GOOS=linux GOARCH=amd64 go build -o $PROJECT_ROOT/bin/networker $PROJECT_ROOT/main.go 14 | if [ $? -ne 0 ]; then 15 | echo "failed to compile networker for linux" && exit 1 16 | fi 17 | 18 | echo "compiling for windows" 19 | GOOS=windows GOARCH=386 go build -o $PROJECT_ROOT/bin/networker.exe $PROJECT_ROOT/main.go 20 | if [ $? -ne 0 ]; then 21 | echo "failed to compile networker for windows" && exit 1 22 | fi 23 | 24 | echo "compiled successfully" -------------------------------------------------------------------------------- /scripts/clean.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | echo "cleaning bin" 4 | rm -rf $(git rev-parse --show-toplevel)/bin > /dev/null 5 | if [ $? -ne 0 ]; then 6 | echo "no binaries to delete" 7 | fi -------------------------------------------------------------------------------- /scripts/doc_gen.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "log" 5 | "os/exec" 6 | "path" 7 | "strings" 8 | 9 | "github.com/fuskovic/networker/v3/cmd" 10 | "github.com/spf13/cobra/doc" 11 | ) 12 | 13 | var projectRoot string 14 | 15 | func init() { 16 | output, _ := exec.Command("git", "rev-parse", "--show-toplevel").CombinedOutput() 17 | projectRoot = strings.Replace(string(output), "\n", "", 1) 18 | } 19 | 20 | func main() { 21 | if err := doc.GenMarkdownTree(cmd.Root, path.Join(projectRoot, "docs")); err != nil { 22 | log.Fatalf("gen markdown tree: %v\n", err) 23 | } 24 | log.Println("docs successfully updated") 25 | } 26 | -------------------------------------------------------------------------------- /scripts/generate_test_coverage_report.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | echo "***** GENERATING COVERAGE REPORT *****" 4 | 5 | go test -coverprofile coverage.out ./... 6 | 7 | if [ $? -ne 0 ]; then 8 | echo "tests failing" 9 | echo "coverage report not generated" 10 | exit 1 11 | fi 12 | 13 | if [ "$1" = "headless" ]; then 14 | echo "***** CHECKING COVERAGE *****" 15 | go tool cover -func coverage.out 16 | else 17 | echo "***** SERVING HTML COVERAGE DIFF... *****" 18 | go tool cover -html coverage.out 19 | fi 20 | 21 | rm coverage.out -------------------------------------------------------------------------------- /scripts/install.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | rm -f $(which networker) > /dev/null 4 | 5 | if [[ -z "$GOBIN" ]]; then 6 | echo "GOBIN unset" 7 | echo "add the following lines to your shells config file" 8 | echo "export GOPATH=\$HOME/go" 9 | echo "export GOBIN=\$GOPATH/bin" 10 | echo "export PATH=\$PATH:\$GOBIN" 11 | exit 1 12 | fi 13 | 14 | echo "installing" 15 | PROJECT_ROOT=$(git rev-parse --show-toplevel) 16 | go install $PROJECT_ROOT 17 | if [ $? -ne 0 ]; then 18 | echo "failed to compile networker" 19 | exit 1 20 | fi 21 | 22 | networker -v 23 | if [ $? -ne 0 ]; then 24 | echo "failed to validate networker installation" 25 | exit 1 26 | fi --------------------------------------------------------------------------------