commit
This commit is contained in:
@@ -0,0 +1,31 @@
|
||||
package netx
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"net"
|
||||
)
|
||||
|
||||
type dns struct{}
|
||||
|
||||
func NewDNS() *dns {
|
||||
return &dns{}
|
||||
}
|
||||
|
||||
|
||||
// 查询A记录,返回IPV4和IPV6的切片
|
||||
func GetA(domain string) ([]string, error) {
|
||||
iprecords, _ := net.LookupIP("facebook.com")
|
||||
for _, ip := range iprecords {
|
||||
fmt.Println(ip)
|
||||
}
|
||||
}
|
||||
|
||||
// 查询CNAME记录
|
||||
func GetCNAME(domain string) (string, error) {
|
||||
cname, _ := net.LookupCNAME("m.facebook.com")
|
||||
fmt.Println(cname)
|
||||
}
|
||||
|
||||
// chaxun
|
||||
|
||||
|
||||
@@ -0,0 +1,30 @@
|
||||
package netx
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"net/http"
|
||||
"net/http/httputil"
|
||||
)
|
||||
|
||||
// 获取http原始报文
|
||||
|
||||
func GetHttpOrigin() {
|
||||
resp, err := http.Get("https://baidu.com")
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
defer resp.Body.Close()
|
||||
|
||||
d, err := httputil.DumpRequestOut(resp.Request, true)
|
||||
fmt.Println(string(d))
|
||||
|
||||
dump, err := httputil.DumpResponse(resp, true)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
dd, err := httputil.DumpRequest(resp.Request, true)
|
||||
fmt.Println(string(dd))
|
||||
|
||||
fmt.Printf("%q", dump)
|
||||
}
|
||||
@@ -0,0 +1,30 @@
|
||||
package httpsx
|
||||
|
||||
import (
|
||||
"crypto/tls"
|
||||
"fmt"
|
||||
"net/http"
|
||||
)
|
||||
|
||||
// 获取HTTPS证书过期时间
|
||||
|
||||
func main() {
|
||||
tr := &http.Transport{
|
||||
TLSClientConfig: &tls.Config{InsecureSkipVerify: true},
|
||||
}
|
||||
client := &http.Client{Transport: tr}
|
||||
|
||||
seedUrl := "https://www.baidu.cn"
|
||||
resp, err := client.Get(seedUrl)
|
||||
defer resp.Body.Close()
|
||||
|
||||
if err != nil {
|
||||
fmt.Errorf(seedUrl, " 请求失败")
|
||||
panic(err)
|
||||
}
|
||||
|
||||
//fmt.Println(resp.TLS.PeerCertificates[0])
|
||||
certInfo := resp.TLS.PeerCertificates[0]
|
||||
fmt.Println("过期时间:", certInfo.NotAfter)
|
||||
fmt.Println("组织信息:", certInfo.Subject)
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
package netx
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"io"
|
||||
"net/http"
|
||||
)
|
||||
|
||||
// 读取POST请求的原始参数
|
||||
func GetOriginParams(r *http.Request) ([]byte, error) {
|
||||
buf := &bytes.Buffer{}
|
||||
tea := io.TeeReader(r.Body, buf)
|
||||
body, err := io.ReadAll(tea)
|
||||
if err != nil && err != io.EOF {
|
||||
return []byte{}, err
|
||||
}
|
||||
r.Body = io.NopCloser(buf)
|
||||
return body, nil
|
||||
}
|
||||
Reference in New Issue
Block a user