Last active
May 5, 2019 21:50
-
-
Save roobre/785fc34dde4dea2f16a55a7c4c83c151 to your computer and use it in GitHub Desktop.
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" | |
"compress/gzip" | |
"encoding/base64" | |
"encoding/json" | |
"fmt" | |
"log" | |
"net/http" | |
"os" | |
"strings" | |
"time" | |
) | |
func main() { | |
log := log.New(os.Stderr, "", 0) | |
resp, _ := http.Get(os.Args[1]) | |
gzipReader, _ := gzip.NewReader(resp.Body) | |
jsonLineReader := bufio.NewReaderSize(gzipReader, 1*1024) | |
var data struct { | |
Data string | |
Path string | |
Host string | |
IP string | |
} | |
printer := make(chan string, 4) | |
go func() { | |
for line := range printer { | |
fmt.Print(line) | |
time.Sleep(333 * time.Millisecond) | |
} | |
}() | |
mainloop: | |
for line, _, err := jsonLineReader.ReadLine(); err == nil; line, _, err = jsonLineReader.ReadLine() { | |
jsonErr := json.Unmarshal(line, &data) | |
if jsonErr != nil { | |
continue | |
} | |
resp, respErr := http.ReadResponse(bufio.NewReader(base64.NewDecoder(base64.StdEncoding, strings.NewReader(data.Data))), nil) | |
if respErr != nil { | |
log.Println(respErr) | |
continue | |
} | |
_ = resp.Body.Close() | |
for _, blacklisted := range []int{ | |
301, 302, | |
401, | |
}{ | |
if resp.StatusCode == blacklisted { | |
continue mainloop | |
} | |
} | |
originalStatus := strings.ToLower(resp.Status) | |
rfcStatus := strings.ToLower(http.StatusText(resp.StatusCode)) | |
for _, blacklisted := range []string{ | |
"service temporarily unavailable", | |
"domain not found", | |
"data follows", | |
"redirect", | |
"timeout", | |
"moved", | |
} { | |
if strings.Contains(originalStatus, blacklisted) { | |
continue mainloop | |
} | |
} | |
if !strings.Contains(originalStatus, rfcStatus) && !strings.Contains(rfcStatus, originalStatus) && len(originalStatus) > 4 { | |
printer <- fmt.Sprintf("%s%s (%s): %s\n", data.Host, data.Path, resp.Header.Get("server"), resp.Status) | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment