You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
117 lines
2.6 KiB
117 lines
2.6 KiB
/*
|
|
*
|
|
@author: sre
|
|
@date: 2022/8/9 0009
|
|
*
|
|
*/
|
|
package main
|
|
|
|
import (
|
|
"bufio"
|
|
"fmt"
|
|
"net"
|
|
"os"
|
|
"strconv"
|
|
"strings"
|
|
)
|
|
|
|
func main() {
|
|
lines, err := readlines("lic.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]
|
|
lenIpPort := len(strings.Split(ipPort, ":"))
|
|
ip := strings.Split(ipPort, ":")[0]
|
|
port := 80
|
|
if lenIpPort == 2 {
|
|
portStr := strings.Split(ipPort, ":")[1]
|
|
port, err = strconv.Atoi(portStr)
|
|
if err != nil {
|
|
fmt.Println("port error:", err)
|
|
writeline("fail.txt", line)
|
|
}
|
|
}
|
|
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("http proxy ", line)
|
|
ipPort := strings.Split(line, "//")[1]
|
|
lenIpPort := len(strings.Split(ipPort, ":"))
|
|
ip := strings.Split(ipPort, ":")[0]
|
|
port := 443
|
|
if lenIpPort == 2 {
|
|
portStr := strings.Split(ipPort, ":")[1]
|
|
port, err = strconv.Atoi(portStr)
|
|
if err != nil {
|
|
fmt.Println("port error:", err)
|
|
writeline("fail.txt", line)
|
|
}
|
|
}
|
|
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, "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
|
|
}
|