Giter Club home page Giter Club logo

dnslookup's Introduction

dnslookup

The dnslookup package provides tools to retrieve DNS records of a given domain.

It has mutex feature in each method so that it prevents problems that may occur related to concurrency.

Installation

Install using the “go get” command:

go get -u github.com/yagizhanbilaldurak/dnslookup

Usage

Create a new instance with NewDnsRecord :

domain := "example.com"
newrecord := NewDnsRecord(domain)

Depending on need, for each DNS record, separate methods can be used.

//for A (IPv4) records
newrecord.GetARecords()

//for CNAME (Canonical Name) records
newrecord.GetCnameRecords()

//for MX (Mail Exchange) records
newrecord.GetMxRecords()

//for NS (Name Server) records
newrecord.GetNsRecords()

//for PTR (Pointer) records
newrecord.GetPtrRecords()

//for TXT (Text) records
newrecords.GetTxtRecords()
If all records (A, CNAME, MX, NS, PTR, TXT) are needed, use simply :

newrecord.GetAllRecords()
//it will return a structured map with string keys and interface{} values.
//The returned map, contains DNS records organized by their record types as keys.

Example Program

With this program, dnslookup package can be used with parameters.

package main

import (
 "flag"
 "fmt"
 "github.com/yagizhanbilaldurak/dnslookup"
)

func main() {
 // Define and parse command-line flags
 domainPtr := flag.String("domain", "", "domain")
 searchTypePtr := flag.String("s", "", "searchType")
 flag.Parse()

 // Retrieve values from command-line flags
 domain := *domainPtr
 searchType := *searchTypePtr

 // Create a DNS record instance
 recorder := dnslookup.NewDnsRecord(domain)

 // Check if the searchType is valid
 if !isValidSearchType(searchType) {
  fmt.Println("error: -domain and -s parameters required. usage: dnssearch -domain example.net -s all")
  return
 } else {
  // Based on the searchType, perform DNS record lookup and print the results
  switch searchType {
  case "a":
   fmt.Println(recorder.GetARecords())
  case "all":
   fmt.Println(recorder.GetAllRecords())
  case "cname":
   fmt.Println(recorder.GetCnameRecords())
  case "mx":
   fmt.Println(recorder.GetMxRecords())
  case "ns":
   fmt.Println(recorder.GetNsRecords())
  case "ptr":
   fmt.Println(recorder.GetPtrRecords())
  case "txt":
   fmt.Println(recorder.GetTxtRecords())
  }
 }

}

func isValidSearchType(searchType string) bool {

 searchOptions := []string{"a", "all", "cname", "mx", "ns", "ptr", "txt"}

 found := true

 for _, v := range searchOptions {
  if searchType != v {
   found = false
  } else {
   return true
  }
 }

 return found

}

Usage

Firstly, program must be built:

go build main.go

Now, run the program with command:

Note: if desired, search type can be change into “a, cname, mx, ns, ptr, txt”.

for a,cname,mx,ns,ptr,txt records; "all" parameter can be used

go run main.go -domain example.net -s all

Output:

map[A records:[93.184.216.34] CNAME records:example.net. MX records:[{. 0}] NS records:[{a.iana-servers.net.} {b.iana-servers.net.}] PTR records:[] TXT records:[v=spf1 -all 4wgz0ccyj83cx2y6xfpmmrp6w2d8gv2v]]

dnslookup's People

Contributors

yagizhanbilaldurak avatar

Stargazers

 avatar  avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.