commit c8a1b06d62dc36cea511800d8cf70a203f5f8ebb Author: dustoair <107600816+dustoair@users.noreply.github.com> Date: Tue Aug 9 11:50:12 2022 +0800 dial test for tcp proxy list diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..8d7a0ab --- /dev/null +++ b/.gitignore @@ -0,0 +1,3 @@ +.idea +go.sum +*.txt \ No newline at end of file diff --git a/go.mod b/go.mod new file mode 100644 index 0000000..898f833 --- /dev/null +++ b/go.mod @@ -0,0 +1,3 @@ +module proxyVerify + +go 1.19 diff --git a/main.go b/main.go new file mode 100644 index 0000000..c5b864a --- /dev/null +++ b/main.go @@ -0,0 +1,93 @@ +/* +* +@author: sre +@date: 2022/8/9 0009 +* +*/ +package main + +import ( + "bufio" + "fmt" + "net" + "os" + "strconv" + "strings" +) + +func main() { + lines, err := readlines("target.txt") + if err != nil { + return + } + for _, line := range lines { + switch { + case strings.Index(line, "http://") == 0: + fmt.Println("http proxy ", line) + ipPort := strings.Split(line, "//")[1] + portStr := strings.Split(ipPort, ":")[1] + port, err := strconv.Atoi(portStr) + if err != nil { + fmt.Println("port error:", err) + } + ip := strings.Split(ipPort, ":")[0] + fmt.Println("ip ", ip) + fmt.Println("port ", port) + if isPortOpen(ip, port) { + fmt.Println("port is open") + fmt.Println("proxy ok") + writeline("success.txt", line) + } else { + fmt.Println("port is not open") + writeline("fail.txt", line) + } + case strings.Index(line, "https://") == 0: + fmt.Println("https proxy ", line) + case strings.Index(line, "socks5://") == 0: + fmt.Println("socks5 proxy ", line) + case strings.Index(line, "socks4://") == 0: + fmt.Println("socks4 proxy ", line) + case strings.Index(line, "socks://") == 0: + fmt.Println("socks proxy ", line) + default: + fmt.Println("unknown proxy ", line) + } + } + +} + +// function to verify a tcp port is open or not +func isPortOpen(host string, port int) bool { + conn, err := net.Dial("tcp", host+":"+strconv.Itoa(port)) + if err != nil { + return false + } + defer conn.Close() + return true +} + +// readlines reads lines from a file and returns a slice of strings. +func readlines(filename string) ([]string, error) { + file, err := os.Open(filename) + if err != nil { + return nil, err + } + defer file.Close() + var lines []string + scanner := bufio.NewScanner(file) + for scanner.Scan() { + lines = append(lines, scanner.Text()) + } + return lines, scanner.Err() +} + +// writeline appends a line to a file. +func writeline(filename string, line string) error { + file, err := os.OpenFile(filename, os.O_CREATE|os.O_APPEND|os.O_WRONLY, 0644) + if err != nil { + return err + } + defer file.Close() + _, err = file.WriteString(line + "\n") + return err +} diff --git a/readme.md b/readme.md new file mode 100644 index 0000000..0801b46 --- /dev/null +++ b/readme.md @@ -0,0 +1,24 @@ +quick tcp proxy dia test, read proxy list file and write to result + +target.txt +``` +socks5://34.92.218.103:20000 +http://34.92.218.103:20000 +https://34.92.218.103:20000 +http://127.0.0.1:8118 +http://123.3.3.4:28118 +``` + +success.txt +``` +``` + +fail.txt +``` +``` + + + +代理可用性批量检测- Python version + +https://kingly.life/2022/07/08/%e4%bb%a3%e7%90%86%e5%8f%af%e7%94%a8%e6%80%a7%e6%89%b9%e9%87%8f%e6%a3%80%e6%b5%8b-python.html \ No newline at end of file