Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- >> Sinden's HTTP IP to Hostname Filter
- Credits to Google and the mind of Sinden.
- Info: Reads a list of ips and resolves them and
- checks the status to see if there online and outputs the online results.
- */
- package main
- import (
- "bufio"
- "fmt"
- "log"
- "net"
- "net/http"
- "os"
- "strings"
- "time"
- )
- func dnshure_online(host string) bool {
- timeout := time.Duration(3 * time.Second)
- client := http.Client{
- Timeout: timeout,
- }
- rs, err := client.Get("http://" + host)
- if err != nil {
- return false
- }
- defer rs.Body.Close()
- return rs.StatusCode == 200
- }
- func dnshure_handle_host(current_host string, file *os.File) {
- rev_dns, err := net.LookupAddr(current_host)
- if err != nil {
- return
- }
- if !dnshure_online(rev_dns[0]) {
- fmt.Printf("[OFFLINE] -> %s | %s\r\n", current_host, rev_dns[0])
- return
- }
- fmt.Printf("[ONLINE] -> %s | %s\r\n", current_host, rev_dns[0])
- if len(rev_dns) > 0 && rev_dns[0] != current_host {
- hostname := strings.TrimSuffix(rev_dns[0], ".")
- fmt.Fprintf(file, hostname+"\r\n")
- } else {
- fmt.Fprintf(file, current_host+"\r\n")
- }
- }
- func main() {
- if len(os.Args) != 3 {
- log.Fatal("Arguments: <ip_list> <out>")
- }
- in_file, err := os.Open(os.Args[1])
- if err != nil {
- log.Fatal(err)
- }
- defer in_file.Close()
- file, err := os.Create(os.Args[2])
- if err != nil {
- log.Fatal(err)
- }
- defer file.Close()
- scanner := bufio.NewScanner(in_file)
- for scanner.Scan() {
- current_host := scanner.Text()
- go dnshure_handle_host(current_host, file)
- }
- input, _ := bufio.NewReader(os.Stdin).ReadString('\n')
- fmt.Printf("You just entered this..%s - terminating!\n", input)
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement