Skip to content

Commit

Permalink
Error handler updated
Browse files Browse the repository at this point in the history
  • Loading branch information
JYThomas committed Aug 30, 2024
1 parent 05caf82 commit 519c511
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 22 deletions.
23 changes: 14 additions & 9 deletions internal/scripts/Certificates/crtsh.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@ package main
import (
"fmt"
"io"
"errors"
"encoding/json"
"Gomain/internal/utils/MakeRequests"
"Gomain/internal/utils/HandleFunc"

)

// 定义用于解析 JSON 的结构体
Expand All @@ -32,24 +32,27 @@ func query(domain string)([]string, error){
// 设置请求配置
request, err := MakeRequests.MakeReq(url)
if err != nil{
panic(err)
// panic 用于处理程序中的严重错误或不可恢复的异常
// panic(err)
return []string{}, errors.New("Create Requests Error")
}

// 发送 HTTP 请求
resp, err := client.Do(request)
if err != nil{
panic(err)
return []string{}, errors.New("Send Requests Error")
}
defer resp.Body.Close()

fmt.Println(resp.StatusCode)
if(resp.StatusCode != 200){
return []string{}, nil
return []string{}, errors.New("Response not 200 Error")
}

// 处理响应内容,提取域名目标
subdomains, err := resolve_resp(resp.Body)
if err != nil{
panic(err)
return []string{}, errors.New("Extract domains Error")
}
result := HandleFunc.RemoveDuplicates(subdomains)
return result, err
Expand All @@ -60,15 +63,15 @@ func resolve_resp(html io.Reader)(result []string, err error){
// 读取响应体 响应内容为json字符串
content, err := io.ReadAll(html)
if err != nil {
return nil, fmt.Errorf("failed to read response body: %w", err)
return []string{}, errors.New("failed to read response body")
}

var certificates []Certificate
// 将Json字符串内容解析为Certificate结构体切片 Json字符串内容与结构体结构相同
err = json.Unmarshal([]byte(content), &certificates)

if err != nil {
return nil, fmt.Errorf("failed to unmarshal JSON: %w", err)
return []string{}, errors.New("failed to unmarshal JSON")
}

for _, cert := range certificates {
Expand All @@ -81,10 +84,12 @@ func resolve_resp(html io.Reader)(result []string, err error){

func main(){
// domain := "bilibili.com"
domain := "gxust.edu.cn"
// domain := "gxust.edu.cn"
domain := "gxu.edu.cn"
subdomains, err := query(domain)
if err != nil{
panic(err)
fmt.Println(1)
fmt.Println(err)
}
fmt.Println(subdomains)
}
28 changes: 15 additions & 13 deletions internal/scripts/DNSSet/chaziyu.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"fmt"
"io"
"strings"
"errors"

"github.com/PuerkitoBio/goquery"
"Gomain/internal/utils/MakeRequests"
Expand All @@ -21,27 +22,28 @@ func query(domain string)([]string, error){
// 设置请求配置
request, err := MakeRequests.MakeReq(url)
if err != nil{
panic(err)
return []string{}, errors.New("Fail to Create Requests")
}

// 发送 HTTP 请求
resp, err := client.Do(request)
if err != nil{
panic(err)
return []string{}, errors.New("Fail to send Requests")
}
defer resp.Body.Close()

if(resp.StatusCode != 200){
return []string{}, errors.New("Response Error: not 200")
}

// 处理响应内容,提取域名目标
if(resp.StatusCode == 200){
subdomains, err := resolve_html(resp.Body)
if err != nil{
panic(err)
}
result := HandleFunc.RemoveDuplicates(subdomains)
return result, nil
subdomains, err := resolve_html(resp.Body)
if err != nil{
return []string{}, errors.New("Fail to extract subdomains")
}

return nil, err
result := HandleFunc.RemoveDuplicates(subdomains)
return result, nil

}


Expand All @@ -51,7 +53,7 @@ func resolve_html(html io.Reader)([]string, error){
domains_slice := make([]string, 0)
doc, err := goquery.NewDocumentFromReader(html)
if err != nil{
panic(err)
return []string{}, errors.New("Fail to read HTML")
}
// 查找所有的表格
doc.Find("table").Each(func(i int, table *goquery.Selection) {
Expand All @@ -73,7 +75,7 @@ func main(){
domain := "bilibili.com"
subdomains, err := query(domain)
if err != nil{
panic(err)
fmt.Println(err)
}
fmt.Println(subdomains)
}

0 comments on commit 519c511

Please sign in to comment.