go_chang922_ip/main.go

79 lines
2.1 KiB
Go
Raw Normal View History

2023-07-28 08:57:50 +08:00
/*
* @Author: giaogiao giaogiao
* @Date: 2023-07-28 08:53:13
* @LastEditors: giaogiao giaogiao
2023-07-28 15:31:48 +08:00
* @LastEditTime: 2023-07-28 15:31:25
2023-07-28 08:57:50 +08:00
* @FilePath: \go\main.go
* @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
*/
package main
import (
2023-07-28 15:10:48 +08:00
"encoding/json"
2023-07-28 08:57:50 +08:00
"fmt"
2023-07-28 15:26:22 +08:00
"hello/setup"
2023-07-28 15:10:48 +08:00
"io/ioutil"
2023-07-28 15:31:48 +08:00
"net/http"
2023-07-28 15:10:48 +08:00
"os"
"strconv"
"time"
"github.com/parnurzeal/gorequest"
2023-07-28 08:57:50 +08:00
)
2023-07-28 15:10:48 +08:00
func read_a_file() {
type Node []struct {
Remarks string `json:"remarks"`
Country string `json:"country"`
Port int `json:"port"`
}
// 打开json文件
jsonFile, err := os.Open("user.json")
// 最好要处理以下错误
if err != nil {
fmt.Println(err)
}
// 要记得关闭
defer jsonFile.Close()
byteValue, _ := ioutil.ReadAll(jsonFile)
var node Node
err = json.Unmarshal(byteValue, &node)
if err != nil {
fmt.Println(err)
}
for _, item := range node {
// fmt.Println(item.Remarks, item.Country, item.Port)
text_url(item.Remarks, item.Country, item.Port)
}
2023-07-28 08:57:50 +08:00
}
2023-07-28 15:10:48 +08:00
func text_url(remarks string, country string, port int) {
2023-07-28 15:26:22 +08:00
setup.CwLog().Infof("start_testing country:%s,port:%d", country, port)
2023-07-28 15:10:48 +08:00
request := gorequest.New().Proxy("socks5://23.224.102.3:" + strconv.Itoa(port))
resp, body, errs := request.Get("https://ip.shagain.club/").End()
if errs != nil {
// fmt.Print(errs)
2023-07-28 15:26:22 +08:00
setup.CwLog().Errorf("start_testing country:%s,port:%d,error:%s", country, port, errs)
setup.CwLog().Infof("start_switching_ip country:%s,port:%d", country, port)
2023-07-28 15:31:48 +08:00
resp, err := http.Get("http://127.0.0.1:9049/v1/ips?num=1&country=" + country + "&state=all&city=all&zip=all&t=txt&port=" + strconv.Itoa(port) + "&isp=all&start=&end=")
setup.CwLog().Infof("switch_ip_to_return resp:%s,err:%s", resp, err)
2023-07-28 15:10:48 +08:00
}
2023-07-28 15:26:22 +08:00
setup.CwLog().Infof("requestToReturnTheResult resp:%s,body:%s", resp, body)
setup.CwLog().Infof("the_current_port_is_fine port:%d", port)
2023-07-28 08:57:50 +08:00
}
2023-07-28 15:10:48 +08:00
2023-07-28 15:26:22 +08:00
func init() {
setup.InitLogger() //初始化log
}
2023-07-28 08:57:50 +08:00
func main() {
2023-07-28 15:26:22 +08:00
setup.CwLog().Warn("start") //测试log
2023-07-28 15:10:48 +08:00
for {
time.Sleep(5000)
read_a_file()
}
2023-07-28 08:57:50 +08:00
}