diff --git a/curl.go b/curl.go index 373c81a..ee3338f 100644 --- a/curl.go +++ b/curl.go @@ -7,6 +7,7 @@ import ( "log" "net" "net/http" + "os" "time" ) @@ -34,6 +35,32 @@ func isValidIP(ip string) bool { return net.ParseIP(ip) != nil } +func SaveBytesToFile(data []byte, filename string, syncToDisk bool) error { + if filename == "" { + return fmt.Errorf("filename cannot be empty") + } + + file, err := os.OpenFile(filename, os.O_APPEND|os.O_CREATE|os.O_WRONLY, 0600) + if err != nil { + return fmt.Errorf("failed to open file %q: %w", filename, err) + } + defer file.Close() + + _, err = file.Write(data) + if err != nil { + return fmt.Errorf("failed to write to file %q: %w", filename, err) + } + + if syncToDisk { + err = file.Sync() + if err != nil { + return fmt.Errorf("failed to sync data to disk for file %q: %w", filename, err) + } + } + + return nil +} + func curl_(IP_ADDR string) (string, error) { var ( err error @@ -98,6 +125,11 @@ func curl_(IP_ADDR string) (string, error) { log.Printf("读取响应体时出错: %v", err) } + // 保存响应体到文件 + if err := SaveBytesToFile(append(HTTP_BODY, '\n'), "response.json", true); err != nil { + log.Printf("failed to save HTTP response to file: %v", err) + } + // 解析 JSON 数据 err = json.Unmarshal(HTTP_BODY, &HTPP_JSON) if err != nil { diff --git a/denyip b/denyip index 35111c1..b5ed7c3 100644 Binary files a/denyip and b/denyip differ