예제 #1
2
func handler(w http.ResponseWriter, r *http.Request) {
	url := r.URL.Query()["q"][0]

	w.Header().Set("Content-Type", "text/html")

	resp, err := http.Get(url)
	if err != nil {
		fmt.Fprintf(w, "%v\n", err)
		return
	}

	img, err := png.Decode(resp.Body)
	if err != nil {
		fmt.Fprintf(w, "%v\n", err)
		return
	}

	for _, s := range crack.Crack(img) {
		fmt.Fprint(w, s.Sym.Char)
	}

	fmt.Fprintf(w, `<img src="%s"/>`, url)
}
예제 #2
0
func main() {
	path := os.Args[1]
	img := OpenImage(path)

	for _, s := range crack.Crack(img) {
		fmt.Print(s.Sym.Char)
	}

	fmt.Println()
}
예제 #3
0
파일: tracker.go 프로젝트: seletskiy/slorry
func TryToBreakCaptcha(number string) string {
	u, err := url.Parse(TrackUrl)
	if err != nil {
		log.Fatal(err)
	}

	resp, err := http.Get(TrackUrl)
	if err != nil {
		log.Fatal(err)
	}

	bytes, err := ioutil.ReadAll(resp.Body)
	if err != nil {
		log.Fatal(err)
	}

	resp, err = http.Get(CaptchaUrl)
	if err != nil {
		log.Fatal(err)
	}

	img, err := png.Decode(resp.Body)

	captchaCode := ""
	for _, sym := range crack.Crack(img) {
		captchaCode += sym.Sym.Char
	}

	jarOpts := cookiejar.Options{
		PublicSuffixList: nil,
	}
	jar, err := cookiejar.New(&jarOpts)
	if err != nil {
		log.Fatal(err)
	}
	jar.SetCookies(u, resp.Cookies())

	c := &http.Client{Jar: jar}
	resp, err = c.PostForm(TrackUrl,
		url.Values{
			"CaptchaCode": {captchaCode},
			"BarCode":     {strings.ToUpper(number)},
			"searchsign":  {"1"},
		})
	if err != nil {
		log.Fatal(err)
	}

	bytes, err = ioutil.ReadAll(resp.Body)

	body := string(bytes)

	capchaErrorMatch := CaptchaErrorRe.FindStringSubmatch(body)
	if len(capchaErrorMatch) > 0 {
		log.Println("неправильно прочитал капчу")
		log.Printf("ссылка на капчу: %s", CaptchaUrl)
		log.Printf("прочитанный код: %s", captchaCode)

		return ""
	}

	return body
}