godns

package module
v0.0.0-...-a43c0fb Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 29, 2024 License: MIT Imports: 9 Imported by: 0

README

Go version Contribute

GoDNS

GoDNS is a Go library for finding IP addresses of targets using reliable resolvers. It's fast, supports both IPv4 and IPv6, and allows for customizable search settings.

Example

go get github.com/root4loot/godns@master
package main

import (
	"fmt"
	"strings"

	"github.com/root4loot/godns"
)

func main() {
	// Options
	options := godns.DefaultOptions()
	options.Concurrency = 5
	options.Timeout = 5
	options.Delay = 0
	options.DelayJitter = 0
	options.Resolvers = []string{"208.67.222.222", "208.67.220.220"}
	
	r := godns.NewRunnerWithOptions(*options)

	// Single domain
	fmt.Println("Single:")

	result := godns.Single("example.com")
	fmt.Printf("Domain: %s\n", result.Domain)

	if len(result.IPv4) > 0 {
		fmt.Printf("IPv4: %s\n", strings.Join(result.IPv4, ", "))
	} else {
		fmt.Println("IPV4: None")
	}
	if len(result.IPv6) > 0 {
		fmt.Printf("IPv6: %s\n", strings.Join(result.IPv6, ", "))
	} else {
		fmt.Println("IPv6: None")
	}
	fmt.Println("Resolver:", result.ResolvedBy)

	// Multiple domains
	fmt.Println("\nMultiple:")

	results := r.Multiple([]string{"example.com", "google.com", "github.com"})
	for _, result := range results {
		fmt.Printf("Domain: %s\n", result.Domain)
		if len(result.IPv4) > 0 {
			fmt.Printf("IPv4: %s\n", strings.Join(result.IPv4, ", "))
		} else {
			fmt.Println("IPV4: None")
		}
		if len(result.IPv6) > 0 {
			fmt.Printf("IPv6: %s\n", strings.Join(result.IPv6, ", "))
		} else {
			fmt.Println("IPv6: None")
		}
		fmt.Println("Resolver:", result.ResolvedBy)
	}

	// Multiple domains using channels
	fmt.Println("\nMultipleStream")

	streamResults := make(chan godns.Result)
	go r.MultipleStream(streamResults, "example.com", "google.com", "github.com")
	for result := range streamResults {
		fmt.Printf("Domain: %s\n", result.Domain)
		if len(result.IPv4) > 0 {
			fmt.Printf("IPv4: %s\n", strings.Join(result.IPv4, ", "))
		} else {
			fmt.Println("IPv4: None")
		}
		if len(result.IPv6) > 0 {
			fmt.Printf("IPv6: %s\n", strings.Join(result.IPv6, ", "))
		} else {
			fmt.Println("IPv6: None")
		}
		fmt.Println("Resolver:", result.ResolvedBy)
	}
}

Contributing

Contributions are welcome. If you find any bugs or have suggestions for improvements, feel free to open an issue or submit a pull request.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Options

type Options struct {
	Concurrency int      // number of concurrent requests
	Timeout     int      // timeout in seconds
	Delay       int      // delay in seconds
	DelayJitter int      // delay jitter in seconds
	Verbose     bool     // verbose logging
	Resolvers   []string // resolvers to use
	Protocol    string   // protocol to use
}

Options contains options for the runner

func DefaultOptions

func DefaultOptions() *Options

DefaultOptions returns default options

type Result

type Result struct {
	Target     string
	IPv4       []string
	IPv6       []string
	ResolvedBy string
}

Result contains the DNS resolution result for a domain.

func Single

func Single(host string, runner ...*Runner) (result Result)

Single resolves a single domain and returns the result

type Runner

type Runner struct {
	Options Options     // options for the runner
	Results chan Result // channel to receive results
}

func NewRunner

func NewRunner() *Runner

NewRunner returns a new runner

func NewRunnerWithOptions

func NewRunnerWithOptions(options Options) *Runner

NewRunnerWithOptions returns a new runner with the specified options

func (*Runner) Multiple

func (r *Runner) Multiple(hosts []string) (results []Result)

Multiple resolves multiple domains and returns the results

func (*Runner) MultipleStream

func (r *Runner) MultipleStream(results chan<- Result, hosts ...string)

MultipleStream resolves multiple domains and streams the results using channels

Directories

Path Synopsis
examples

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL