├── README.md ├── main.go ├── cmd ├── root.go └── trace.go ├── internal └── models │ └── ip.go ├── go.mod ├── .gitignore ├── LICENSE └── go.sum /README.md: -------------------------------------------------------------------------------- 1 | CLI based app to track IP -------------------------------------------------------------------------------- /main.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import "IP-Tracker__-CLI-APP-/cmd" 4 | 5 | // HOW TO RUN: go build -> namegobuild trace ipaddres 6 | func main() { 7 | cmd.Execute() 8 | } 9 | -------------------------------------------------------------------------------- /cmd/root.go: -------------------------------------------------------------------------------- 1 | package cmd 2 | 3 | import "github.com/spf13/cobra" 4 | 5 | var rootCmd = &cobra.Command{ 6 | Use: "Trace", 7 | Short: "IP-Tracker", 8 | Long: `IP-Tracker__-CLI-APP-`, 9 | } 10 | 11 | // Execute executes the root command. 12 | func Execute() error { 13 | return rootCmd.Execute() 14 | } 15 | -------------------------------------------------------------------------------- /internal/models/ip.go: -------------------------------------------------------------------------------- 1 | package models 2 | 3 | type Ip struct { 4 | IP string `json:"ip"` 5 | City string `json:"city"` 6 | Region string `json:"region"` 7 | Country string `json:"country"` 8 | Loc string `json:"loc"` 9 | Timezone string `json:"timezone"` 10 | Postal string `json:"postal"` 11 | } 12 | -------------------------------------------------------------------------------- /go.mod: -------------------------------------------------------------------------------- 1 | module IP-Tracker__-CLI-APP- 2 | 3 | go 1.19 4 | 5 | require ( 6 | github.com/fatih/color v1.15.0 7 | github.com/spf13/cobra v1.7.0 8 | ) 9 | 10 | require ( 11 | github.com/inconshreveable/mousetrap v1.1.0 // indirect 12 | github.com/mattn/go-colorable v0.1.13 // indirect 13 | github.com/mattn/go-isatty v0.0.17 // indirect 14 | github.com/spf13/pflag v1.0.5 // indirect 15 | golang.org/x/sys v0.6.0 // indirect 16 | ) 17 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # If you prefer the allow list template instead of the deny list, see community template: 2 | # https://github.com/github/gitignore/blob/main/community/Golang/Go.AllowList.gitignore 3 | # 4 | # Binaries for programs and plugins 5 | *.exe 6 | *.exe~ 7 | *.dll 8 | *.so 9 | *.dylib 10 | *.env 11 | *env.sh 12 | 13 | # Test binary, built with `go test -c` 14 | *.test 15 | 16 | # Output of the go coverage tool, specifically when used with LiteIDE 17 | *.out 18 | *.idea 19 | 20 | # Dependency directories (remove the comment below to include it) 21 | # vendor/ 22 | 23 | # Go workspace file 24 | go.work 25 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2023 EchoEdyP 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 | -------------------------------------------------------------------------------- /cmd/trace.go: -------------------------------------------------------------------------------- 1 | package cmd 2 | 3 | import ( 4 | "IP-Tracker__-CLI-APP-/internal/models" 5 | "encoding/json" 6 | "fmt" 7 | "github.com/fatih/color" 8 | "github.com/spf13/cobra" 9 | "io" 10 | "log" 11 | "net/http" 12 | ) 13 | 14 | var traceCmd = &cobra.Command{ 15 | Use: "trace", 16 | Short: "trace the IP", 17 | Long: `trace the IP.`, 18 | Run: func(cmd *cobra.Command, args []string) { 19 | if len(args) > 0 { 20 | for _, ip := range args { 21 | showData(ip) 22 | } 23 | } else { 24 | fmt.Println("Please provide IP to trace") 25 | } 26 | }, 27 | } 28 | 29 | func init() { 30 | rootCmd.AddCommand(traceCmd) 31 | } 32 | 33 | func showData(ip string) { 34 | url := "http://ipinfo.io/" + ip + "/geo" 35 | responseByte := getData(url) 36 | 37 | data := models.Ip{} 38 | 39 | err := json.Unmarshal(responseByte, &data) 40 | if err != nil { 41 | log.Println("Unable to unmarshal the response") 42 | } 43 | 44 | c := color.New(color.FgRed).Add(color.Underline).Add(color.Bold) 45 | c.Println("DATA FOUND :") 46 | 47 | fmt.Printf("IP :%s\nCITY :%s\nREGION :%s\nCOUNTRY :%s\nLOCATION :%s\nTIMEZONE:%s\nPOSTAL :%s\n", data.IP, data.City, data.Region, data.Country, data.Loc, data.Timezone, data.Postal) 48 | 49 | } 50 | 51 | func getData(url string) []byte { 52 | 53 | response, err := http.Get(url) 54 | if err != nil { 55 | log.Println("Unable to get the response") 56 | } 57 | 58 | responseByte, err := io.ReadAll(response.Body) 59 | if err != nil { 60 | log.Println("Unable to read the response") 61 | } 62 | 63 | return responseByte 64 | } 65 | -------------------------------------------------------------------------------- /go.sum: -------------------------------------------------------------------------------- 1 | github.com/cpuguy83/go-md2man/v2 v2.0.2/go.mod h1:tgQtvFlXSQOSOSIRvRPT7W67SCa46tRHOmNcaadrF8o= 2 | github.com/fatih/color v1.15.0 h1:kOqh6YHBtK8aywxGerMG2Eq3H6Qgoqeo13Bk2Mv/nBs= 3 | github.com/fatih/color v1.15.0/go.mod h1:0h5ZqXfHYED7Bhv2ZJamyIOUej9KtShiJESRwBDUSsw= 4 | github.com/inconshreveable/mousetrap v1.1.0 h1:wN+x4NVGpMsO7ErUn/mUI3vEoE6Jt13X2s0bqwp9tc8= 5 | github.com/inconshreveable/mousetrap v1.1.0/go.mod h1:vpF70FUmC8bwa3OWnCshd2FqLfsEA9PFc4w1p2J65bw= 6 | github.com/mattn/go-colorable v0.1.13 h1:fFA4WZxdEF4tXPZVKMLwD8oUnCTTo08duU7wxecdEvA= 7 | github.com/mattn/go-colorable v0.1.13/go.mod h1:7S9/ev0klgBDR4GtXTXX8a3vIGJpMovkB8vQcUbaXHg= 8 | github.com/mattn/go-isatty v0.0.16/go.mod h1:kYGgaQfpe5nmfYZH+SKPsOc2e4SrIfOl2e/yFXSvRLM= 9 | github.com/mattn/go-isatty v0.0.17 h1:BTarxUcIeDqL27Mc+vyvdWYSL28zpIhv3RoTdsLMPng= 10 | github.com/mattn/go-isatty v0.0.17/go.mod h1:kYGgaQfpe5nmfYZH+SKPsOc2e4SrIfOl2e/yFXSvRLM= 11 | github.com/russross/blackfriday/v2 v2.1.0/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM= 12 | github.com/spf13/cobra v1.7.0 h1:hyqWnYt1ZQShIddO5kBpj3vu05/++x6tJ6dg8EC572I= 13 | github.com/spf13/cobra v1.7.0/go.mod h1:uLxZILRyS/50WlhOIKD7W6V5bgeIt+4sICxh6uRMrb0= 14 | github.com/spf13/pflag v1.0.5 h1:iy+VFUOCP1a+8yFto/drg2CJ5u0yRoB7fZw3DKv/JXA= 15 | github.com/spf13/pflag v1.0.5/go.mod h1:McXfInJRrz4CZXVZOBLb0bTZqETkiAhM9Iw0y3An2Bg= 16 | golang.org/x/sys v0.0.0-20220811171246-fbc7d0a398ab/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= 17 | golang.org/x/sys v0.6.0 h1:MVltZSvRTcU2ljQOhs94SXPftV6DCNnZViHeQps87pQ= 18 | golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= 19 | gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= 20 | gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= 21 | --------------------------------------------------------------------------------