Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
godnslookup.go
package main
import (
"bufio"
"fmt"
"log"
"os"
"path/filepath"
"time"
"net"
)
func MakeRequest(domain string) {
ips, err := net.LookupIP(domain)
if err != nil {
fmt.Fprintf(os.Stderr, "Could not get IPs")
logger.Println("Could not get IPs")
}
for _, ip := range ips {
fmt.Printf(domain + ". IN A %s\n", ip.String())
logger.Println(domain + ". IN A " + ip.String() + "\n")
}
}
func execute_it(cmdSource string){
t := time.Now()
formattedTime := fmt.Sprintf("%d-%02d-%02d %02d:%02d:%02d",
t.Year(), t.Month(), t.Day(),
t.Hour(), t.Minute(), t.Second())
MakeRequest(cmdSource)
t = time.Now()
formattedTime = fmt.Sprintf("%d-%02d-%02d %02d:%02d:%02d",
t.Year(), t.Month(), t.Day(),
t.Hour(), t.Minute(), t.Second())
fmt.Printf(cmdSource + " queried at %s \n\n", formattedTime)
logger.Println(cmdSource + " queried at " + formattedTime + "\n\n")
time.Sleep(4 * time.Second)
}
func queryandexecute() {
/// generate winbins.txt using dir /b /s c:\windows\*.exe > winbins.txt
file, err := os.Open(fileDomain)
if err != nil {
log.Fatal(err)
}
defer file.Close()
scanner := bufio.NewScanner(file)
for scanner.Scan() {
path:= scanner.Text()
file := filepath.Base(path)
fmt.Println(file)
execute_it(file)
}
if err := scanner.Err(); err != nil {
log.Fatal(err)
}
}
var (
outfile, _ = os.Create("lookup.log") // update path for your needs
fileDomain = "domains.txt"
logger = log.New(outfile, "", 0)
)
func main(){
queryandexecute()
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment