Created
September 28, 2020 04:48
-
-
Save yehgdotnet/5150e9ef3ef40d44abe4458a4a6cb700 to your computer and use it in GitHub Desktop.
godnslookup.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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