Skip to content

Commit 74b550d

Browse files
committed
add getUrlHash.go 计算urlbodymd5小工具
1 parent 61887b9 commit 74b550d

File tree

4,591 files changed

+126
-1398310
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

4,591 files changed

+126
-1398310
lines changed

test/getUrlHash.go

Lines changed: 125 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,125 @@
1+
package main
2+
3+
import (
4+
"crypto/md5"
5+
"crypto/tls"
6+
"fmt"
7+
"io/ioutil"
8+
"net/http"
9+
"os"
10+
"strings"
11+
"time"
12+
)
13+
14+
//func InsertInto(s string, interval int, sep rune) string {
15+
// var buffer bytes.Buffer
16+
// before := interval - 1
17+
// last := len(s) - 1
18+
// for i, char := range s {
19+
// buffer.WriteRune(char)
20+
// if i%interval == before && i != last {
21+
// buffer.WriteRune(sep)
22+
// }
23+
// }
24+
// buffer.WriteRune(sep)
25+
// return buffer.String()
26+
//}
27+
28+
//func FaviconHash(data []byte) int32 {
29+
// stdBase64 := base64.StdEncoding.EncodeToString(data)
30+
// stdBase64 = InsertInto(stdBase64, 76, '\n')
31+
// hasher := murmur3.New32WithSeed(0)
32+
// hasher.Write([]byte(stdBase64))
33+
// return int32(hasher.Sum32())
34+
//}
35+
36+
//func favicohash(host string) string {
37+
// timeout := time.Duration(8 * time.Second)
38+
// var tr *http.Transport
39+
//
40+
// tr = &http.Transport{
41+
// MaxIdleConnsPerHost: -1,
42+
// TLSClientConfig: &tls.Config{InsecureSkipVerify: true},
43+
// DisableKeepAlives: true,
44+
// }
45+
// client := http.Client{
46+
// Timeout: timeout,
47+
// Transport: tr,
48+
// CheckRedirect: func(req *http.Request, via []*http.Request) error {
49+
// return http.ErrUseLastResponse /* 不进入重定向 */
50+
// },
51+
// }
52+
// resp, err := client.Get(host)
53+
// if err != nil {
54+
// //log.Println("favicon client error:", err)
55+
// return "0"
56+
// }
57+
// defer resp.Body.Close()
58+
// if resp.StatusCode == 200 {
59+
// body, err := ioutil.ReadAll(resp.Body)
60+
// if err != nil {
61+
// //log.Println("favicon file read error: ", err)
62+
// return "0"
63+
// }
64+
// faviconMMH3 := fmt.Sprintf("%d", FaviconHash(body))
65+
// return faviconMMH3
66+
// } else {
67+
// return "0"
68+
// }
69+
//}
70+
71+
func favicohashMd5(host string) string {
72+
timeout := time.Duration(8 * time.Second)
73+
var tr *http.Transport
74+
75+
tr = &http.Transport{
76+
MaxIdleConnsPerHost: -1,
77+
TLSClientConfig: &tls.Config{InsecureSkipVerify: true},
78+
DisableKeepAlives: true,
79+
}
80+
client := http.Client{
81+
Timeout: timeout,
82+
Transport: tr,
83+
CheckRedirect: func(req *http.Request, via []*http.Request) error {
84+
return http.ErrUseLastResponse /* 不进入重定向 */
85+
},
86+
}
87+
resp, err := client.Get(host)
88+
if err != nil {
89+
//log.Println("favicon client error:", err)
90+
return "0"
91+
}
92+
defer resp.Body.Close()
93+
if resp.StatusCode == 200 {
94+
body, err := ioutil.ReadAll(resp.Body)
95+
if err != nil {
96+
//log.Println("favicon file read error: ", err)
97+
return "0"
98+
}
99+
srcCode := md5.Sum(body)
100+
faviconMMH3 := strings.ToLower(fmt.Sprintf("%x", srcCode))
101+
return faviconMMH3
102+
} else {
103+
return "0"
104+
}
105+
}
106+
func main() {
107+
url := os.Args[1]
108+
s1 := favicohashMd5(url)
109+
fmt.Println(s1)
110+
//url := os.Args[1]
111+
//resp, err := http.Get(url)
112+
//if err != nil {
113+
// fmt.Println(fmt.Sprintf("url访问出错:%s", err))
114+
// os.Exit(1)
115+
//}
116+
//body, err := ioutil.ReadAll(resp.Body)
117+
//if err != nil {
118+
// fmt.Println(fmt.Sprintf("读取body数据出错:%s", err))
119+
// os.Exit(1)
120+
//}
121+
//// 进行md5加密,因为Sum函数接受的是字节数组,因此需要注意类型转换
122+
//srcCode := md5.Sum(body)
123+
//// md5.Sum函数加密后返回的是字节数组,转换成16进制形式,并全小写
124+
//fmt.Println(strings.ToLower(fmt.Sprintf("%x", srcCode)))
125+
}

test/testXml.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import (
77

88
//var Naabubuffer bytes.Buffer = bytes.Buffer{}
99

10-
func main() {
10+
func main9() {
1111

1212
s := "http://www.ddd.com:990/xxp"
1313
if u, err := url.Parse(s); err == nil {

vendor/github.com/AndreasBriese/bbloom/.travis.yml

Lines changed: 0 additions & 1 deletion
This file was deleted.

vendor/github.com/AndreasBriese/bbloom/LICENSE

Lines changed: 0 additions & 35 deletions
This file was deleted.

vendor/github.com/AndreasBriese/bbloom/README.md

Lines changed: 0 additions & 131 deletions
This file was deleted.

0 commit comments

Comments
 (0)