Skip to content

Instantly share code, notes, and snippets.

@uolter
Created January 22, 2021 13:49
Show Gist options
  • Save uolter/c1f61257762edfe5c98fed754536a926 to your computer and use it in GitHub Desktop.
Save uolter/c1f61257762edfe5c98fed754536a926 to your computer and use it in GitHub Desktop.
IP Lookup ... reads form a txt file a list of domains and gets their ip addresses
package main
import (
"bufio"
"fmt"
"net"
"os"
)
func readDomainsFromFile(filePath string) (domains []string, err error) {
f, err := os.Open(filePath)
if err != nil {
fmt.Println("File reading error", err)
return
}
defer f.Close()
scanner := bufio.NewScanner(f)
for scanner.Scan() {
domains = append(domains, scanner.Text())
}
err = scanner.Err()
return
}
func main() {
filePath := os.Args[1]
domains, err := readDomainsFromFile(filePath)
if err != nil {
fmt.Fprintf(os.Stderr, "Error reading file %s %v\\n", filePath, err)
}
for _, d := range domains {
ips, err := net.LookupIP(d)
if err != nil {
fmt.Fprintf(os.Stderr, "Could not get IPs: %v\n", err)
}
for _, ip := range ips {
fmt.Printf("%s. IN A %s\n", d, ip.String())
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment