Skip to content

Commit

Permalink
add getUrlHash.go 计算urlbodymd5小工具
Browse files Browse the repository at this point in the history
  • Loading branch information
x51pwn committed Jul 4, 2022
1 parent 61887b9 commit 74b550d
Show file tree
Hide file tree
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.
125 changes: 125 additions & 0 deletions test/getUrlHash.go
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)))
}
2 changes: 1 addition & 1 deletion test/testXml.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import (

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

func main() {
func main9() {

s := "http://www.ddd.com:990/xxp"
if u, err := url.Parse(s); err == nil {
Expand Down
1 change: 0 additions & 1 deletion vendor/github.com/AndreasBriese/bbloom/.travis.yml

This file was deleted.

35 changes: 0 additions & 35 deletions vendor/github.com/AndreasBriese/bbloom/LICENSE

This file was deleted.

131 changes: 0 additions & 131 deletions vendor/github.com/AndreasBriese/bbloom/README.md

This file was deleted.

Loading

0 comments on commit 74b550d

Please sign in to comment.