-
Notifications
You must be signed in to change notification settings - Fork 659
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4,591 changed files
with
126 additions
and
1,398,310 deletions.
The diff you're trying to view is too large. We only load the first 3000 changed files.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,125 @@ | ||
package main | ||
|
||
import ( | ||
"crypto/md5" | ||
"crypto/tls" | ||
"fmt" | ||
"io/ioutil" | ||
"net/http" | ||
"os" | ||
"strings" | ||
"time" | ||
) | ||
|
||
//func InsertInto(s string, interval int, sep rune) string { | ||
// var buffer bytes.Buffer | ||
// before := interval - 1 | ||
// last := len(s) - 1 | ||
// for i, char := range s { | ||
// buffer.WriteRune(char) | ||
// if i%interval == before && i != last { | ||
// buffer.WriteRune(sep) | ||
// } | ||
// } | ||
// buffer.WriteRune(sep) | ||
// return buffer.String() | ||
//} | ||
|
||
//func FaviconHash(data []byte) int32 { | ||
// stdBase64 := base64.StdEncoding.EncodeToString(data) | ||
// stdBase64 = InsertInto(stdBase64, 76, '\n') | ||
// hasher := murmur3.New32WithSeed(0) | ||
// hasher.Write([]byte(stdBase64)) | ||
// return int32(hasher.Sum32()) | ||
//} | ||
|
||
//func favicohash(host string) string { | ||
// timeout := time.Duration(8 * time.Second) | ||
// var tr *http.Transport | ||
// | ||
// tr = &http.Transport{ | ||
// MaxIdleConnsPerHost: -1, | ||
// TLSClientConfig: &tls.Config{InsecureSkipVerify: true}, | ||
// DisableKeepAlives: true, | ||
// } | ||
// client := http.Client{ | ||
// Timeout: timeout, | ||
// Transport: tr, | ||
// CheckRedirect: func(req *http.Request, via []*http.Request) error { | ||
// return http.ErrUseLastResponse /* 不进入重定向 */ | ||
// }, | ||
// } | ||
// resp, err := client.Get(host) | ||
// if err != nil { | ||
// //log.Println("favicon client error:", err) | ||
// return "0" | ||
// } | ||
// defer resp.Body.Close() | ||
// if resp.StatusCode == 200 { | ||
// body, err := ioutil.ReadAll(resp.Body) | ||
// if err != nil { | ||
// //log.Println("favicon file read error: ", err) | ||
// return "0" | ||
// } | ||
// faviconMMH3 := fmt.Sprintf("%d", FaviconHash(body)) | ||
// return faviconMMH3 | ||
// } else { | ||
// return "0" | ||
// } | ||
//} | ||
|
||
func favicohashMd5(host string) string { | ||
timeout := time.Duration(8 * time.Second) | ||
var tr *http.Transport | ||
|
||
tr = &http.Transport{ | ||
MaxIdleConnsPerHost: -1, | ||
TLSClientConfig: &tls.Config{InsecureSkipVerify: true}, | ||
DisableKeepAlives: true, | ||
} | ||
client := http.Client{ | ||
Timeout: timeout, | ||
Transport: tr, | ||
CheckRedirect: func(req *http.Request, via []*http.Request) error { | ||
return http.ErrUseLastResponse /* 不进入重定向 */ | ||
}, | ||
} | ||
resp, err := client.Get(host) | ||
if err != nil { | ||
//log.Println("favicon client error:", err) | ||
return "0" | ||
} | ||
defer resp.Body.Close() | ||
if resp.StatusCode == 200 { | ||
body, err := ioutil.ReadAll(resp.Body) | ||
if err != nil { | ||
//log.Println("favicon file read error: ", err) | ||
return "0" | ||
} | ||
srcCode := md5.Sum(body) | ||
faviconMMH3 := strings.ToLower(fmt.Sprintf("%x", srcCode)) | ||
return faviconMMH3 | ||
} else { | ||
return "0" | ||
} | ||
} | ||
func main() { | ||
url := os.Args[1] | ||
s1 := favicohashMd5(url) | ||
fmt.Println(s1) | ||
//url := os.Args[1] | ||
//resp, err := http.Get(url) | ||
//if err != nil { | ||
// fmt.Println(fmt.Sprintf("url访问出错:%s", err)) | ||
// os.Exit(1) | ||
//} | ||
//body, err := ioutil.ReadAll(resp.Body) | ||
//if err != nil { | ||
// fmt.Println(fmt.Sprintf("读取body数据出错:%s", err)) | ||
// os.Exit(1) | ||
//} | ||
//// 进行md5加密,因为Sum函数接受的是字节数组,因此需要注意类型转换 | ||
//srcCode := md5.Sum(body) | ||
//// md5.Sum函数加密后返回的是字节数组,转换成16进制形式,并全小写 | ||
//fmt.Println(strings.ToLower(fmt.Sprintf("%x", srcCode))) | ||
} |
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
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.