├── static └── revit.png ├── go.mod ├── internal └── revit │ ├── types.go │ ├── lookup.go │ ├── stdin.go │ └── file.go ├── go.sum ├── LICENSE ├── README.md └── cmd └── revit └── main.go /static/revit.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/devanshbatham/revit/HEAD/static/revit.png -------------------------------------------------------------------------------- /go.mod: -------------------------------------------------------------------------------- 1 | module github.com/devanshbatham/revit 2 | 3 | go 1.20 4 | 5 | require github.com/fatih/color v1.15.0 6 | 7 | require ( 8 | github.com/mattn/go-colorable v0.1.13 // indirect 9 | github.com/mattn/go-isatty v0.0.17 // indirect 10 | golang.org/x/sys v0.6.0 // indirect 11 | github.com/devanshbatham/revit/internal/revit v0.0.1 12 | ) 13 | -------------------------------------------------------------------------------- /internal/revit/types.go: -------------------------------------------------------------------------------- 1 | package revit 2 | 3 | // LookupResult represents the result of a reverse DNS lookup. 4 | type LookupResult struct { 5 | IPAddress string // The IP address for which the lookup was performed 6 | DNSNames []string // List of resolved DNS names associated with the IP address 7 | Error error // Any error that occurred during the lookup process 8 | } 9 | -------------------------------------------------------------------------------- /go.sum: -------------------------------------------------------------------------------- 1 | github.com/fatih/color v1.15.0 h1:kOqh6YHBtK8aywxGerMG2Eq3H6Qgoqeo13Bk2Mv/nBs= 2 | github.com/fatih/color v1.15.0/go.mod h1:0h5ZqXfHYED7Bhv2ZJamyIOUej9KtShiJESRwBDUSsw= 3 | github.com/mattn/go-colorable v0.1.13 h1:fFA4WZxdEF4tXPZVKMLwD8oUnCTTo08duU7wxecdEvA= 4 | github.com/mattn/go-colorable v0.1.13/go.mod h1:7S9/ev0klgBDR4GtXTXX8a3vIGJpMovkB8vQcUbaXHg= 5 | github.com/mattn/go-isatty v0.0.16/go.mod h1:kYGgaQfpe5nmfYZH+SKPsOc2e4SrIfOl2e/yFXSvRLM= 6 | github.com/mattn/go-isatty v0.0.17 h1:BTarxUcIeDqL27Mc+vyvdWYSL28zpIhv3RoTdsLMPng= 7 | github.com/mattn/go-isatty v0.0.17/go.mod h1:kYGgaQfpe5nmfYZH+SKPsOc2e4SrIfOl2e/yFXSvRLM= 8 | golang.org/x/sys v0.0.0-20220811171246-fbc7d0a398ab/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= 9 | golang.org/x/sys v0.6.0 h1:MVltZSvRTcU2ljQOhs94SXPftV6DCNnZViHeQps87pQ= 10 | golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= 11 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2023 Devansh Batham 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. -------------------------------------------------------------------------------- /internal/revit/lookup.go: -------------------------------------------------------------------------------- 1 | package revit 2 | 3 | import ( 4 | "net" 5 | "context" 6 | ) 7 | 8 | // LookupAddr performs reverse DNS lookup for the given IP address using the specified resolver. 9 | // It sends the lookup results (IP address, resolved DNS names, and any errors) to the results channel. 10 | func LookupAddr(ip string, results chan<- LookupResult, sem chan struct{}, resolver string) { 11 | // Acquire a semaphore to limit the level of concurrency 12 | sem <- struct{}{} 13 | defer func() { <-sem }() 14 | 15 | // Initialize a net.Resolver for performing DNS lookups 16 | var r *net.Resolver 17 | if resolver != "" { 18 | // Create a custom dialer for the resolver 19 | dialer := &net.Dialer{} 20 | r = &net.Resolver{ 21 | PreferGo: true, 22 | Dial: func(ctx context.Context, network, address string) (net.Conn, error) { 23 | return dialer.DialContext(ctx, "udp", resolver+":53") 24 | }, 25 | } 26 | } else { 27 | r = net.DefaultResolver 28 | } 29 | 30 | // Perform a reverse DNS lookup using the Resolver 31 | names, err := r.LookupAddr(context.Background(), ip) 32 | 33 | // Send the lookup results (IP address, resolved DNS names, and errors) to the results channel 34 | results <- LookupResult{ 35 | IPAddress: ip, 36 | DNSNames: names, 37 | Error: err, 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /internal/revit/stdin.go: -------------------------------------------------------------------------------- 1 | package revit 2 | 3 | import ( 4 | "bufio" 5 | "fmt" 6 | "os" 7 | "sync" 8 | "math/rand" 9 | "time" 10 | ) 11 | 12 | // ProcessStdin reads IP addresses from the standard input (stdin), performs DNS lookup 13 | // for each IP, and sends the results to the results channel. 14 | func ProcessStdin(results chan<- LookupResult, sem chan struct{}, wg *sync.WaitGroup, resolvers []string) { 15 | // Create a scanner to read input from the standard input (stdin) 16 | scanner := bufio.NewScanner(os.Stdin) 17 | 18 | // Seed the random number generator with the current time 19 | rand.Seed(time.Now().UnixNano()) 20 | 21 | // Loop through each line in the input 22 | for scanner.Scan() { 23 | ip := scanner.Text() 24 | 25 | // Increment the wait group count for each IP address 26 | wg.Add(1) 27 | 28 | // Launch a goroutine to perform DNS lookup for the IP address 29 | go func(ipAddress string) { 30 | defer wg.Done() 31 | 32 | // Select a random resolver from the provided list 33 | selectedResolver := "" 34 | if len(resolvers) > 0 { 35 | selectedResolver = resolvers[rand.Intn(len(resolvers))] 36 | } 37 | 38 | // Call the LookupAddr function to perform reverse DNS lookup 39 | LookupAddr(ipAddress, results, sem, selectedResolver) 40 | }(ip) 41 | } 42 | 43 | // Check for errors while reading from stdin 44 | if err := scanner.Err(); err != nil { 45 | fmt.Fprintf(os.Stderr, "Failed to read from stdin: %v\n", err) 46 | } 47 | } 48 | -------------------------------------------------------------------------------- /internal/revit/file.go: -------------------------------------------------------------------------------- 1 | package revit 2 | 3 | import ( 4 | "bufio" 5 | "fmt" 6 | "os" 7 | "sync" 8 | "math/rand" 9 | "time" 10 | ) 11 | 12 | // ProcessFile reads IP addresses from a file, performs DNS lookup for each IP, 13 | // and sends the results to the results channel. 14 | func ProcessFile(filename string, results chan<- LookupResult, sem chan struct{}, wg *sync.WaitGroup, resolvers []string) { 15 | // Open the specified file for reading IP addresses 16 | file, err := os.Open(filename) 17 | if err != nil { 18 | fmt.Fprintf(os.Stderr, "Failed to open file: %v\n", err) 19 | return 20 | } 21 | defer file.Close() 22 | 23 | // Seed the random number generator with the current time 24 | rand.Seed(time.Now().UnixNano()) 25 | 26 | // Create a scanner to read IP addresses from the file line by line 27 | scanner := bufio.NewScanner(file) 28 | for scanner.Scan() { 29 | ip := scanner.Text() 30 | 31 | // Increment the wait group count for each IP address 32 | wg.Add(1) 33 | 34 | // Launch a goroutine to perform DNS lookup for the IP address 35 | go func(ipAddress string) { 36 | defer wg.Done() 37 | 38 | // Select a random resolver from the provided list 39 | selectedResolver := "" 40 | if len(resolvers) > 0 { 41 | selectedResolver = resolvers[rand.Intn(len(resolvers))] 42 | } 43 | 44 | // Call the LookupAddr function to perform reverse DNS lookup 45 | LookupAddr(ipAddress, results, sem, selectedResolver) 46 | }(ip) 47 | } 48 | 49 | // Check for errors while scanning the file 50 | if err := scanner.Err(); err != nil { 51 | fmt.Fprintf(os.Stderr, "Failed to read file: %v\n", err) 52 | } 53 | } 54 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 |
10 | 🏗️ Install
11 | ⛏️ Usage
12 |
13 |