forked from quzard/netflix-all-verify
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
204 lines (182 loc) · 4.49 KB
/
main.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
package main
import (
"context"
"fmt"
"github.com/Dreamacro/clash/constant"
"github.com/Dreamacro/clash/hub/executor"
"github.com/Dreamacro/clash/listener/http"
"github.com/axgle/mahonia" //编码转换
"github.com/xuri/excelize/v2"
"io"
"io/ioutil"
"net"
h "net/http"
"net/url"
"netflix-all-verify/nf"
"os"
"path/filepath"
"strconv"
"time"
)
var proxy constant.Proxy
var proxyUrl = "127.0.0.1:"
var exPath string
func getIP() string {
proxy, _ := url.Parse("http://" + proxyUrl)
client := h.Client{
Timeout: 5 * time.Second,
Transport: &h.Transport{
// 设置代理
Proxy: h.ProxyURL(proxy),
},
}
resp, err := client.Get("http://myexternalip.com/raw")
if err != nil {
return ""
}
defer resp.Body.Close()
content, _ := ioutil.ReadAll(resp.Body)
return string(content)
}
func relay(l, r net.Conn) {
go io.Copy(l, r)
io.Copy(r, l)
}
// 获取可用端口
func GetAvailablePort() (int, error) {
address, err := net.ResolveTCPAddr("tcp", fmt.Sprintf("%s:0", "127.0.0.1"))
if err != nil {
return 0, err
}
listener, err := net.ListenTCP("tcp", address)
if err != nil {
return 0, err
}
defer listener.Close()
return listener.Addr().(*net.TCPAddr).Port, nil
}
func downloadConfig() {
ex, err := os.Executable()
if err != nil {
panic(err)
}
exPath = filepath.Dir(ex)
fmt.Println(exPath)
//输入订阅链接
fmt.Println("请输入clash订阅链接(非clash订阅请进行订阅转换)")
var urlConfig string
_, err = fmt.Scanln(&urlConfig)
if err != nil {
panic(err)
}
//下载配置信息
res, err := h.Get(urlConfig)
if err != nil {
fmt.Println("clash的订阅链接下载失败!")
time.Sleep(10 * time.Second)
return
}
defer func(Body io.ReadCloser) {
err := Body.Close()
if err != nil {
panic(err)
}
}(res.Body)
//创建配置文件
f, err := os.OpenFile(exPath+"/config.yaml", os.O_CREATE|os.O_RDWR|os.O_TRUNC, 0777)
defer func(f *os.File) {
err := f.Close()
if err != nil {
panic(err)
}
}(f)
if err != nil {
fmt.Println("clash的订阅链接下载失败!")
time.Sleep(10 * time.Second)
return
}
_, err = io.Copy(f, res.Body)
if err != nil {
panic(err)
}
}
func main() {
downloadConfig()
//解析配置信息
config, err := executor.ParseWithPath(exPath + "/config.yaml")
if err != nil {
return
}
//获取端口
port, _ := GetAvailablePort()
proxyUrl += strconv.Itoa(port)
//开启代理
in := make(chan constant.ConnContext, 100)
defer close(in)
l, err := http.New(proxyUrl, in)
if err != nil {
panic(err)
}
defer l.Close()
println("listen at:", l.Address())
//设置编码
enc := mahonia.NewDecoder("utf8")
//监听代理
go func() {
for c := range in {
conn := c
metadata := conn.Metadata()
go func() {
remote, err := proxy.DialContext(context.Background(), metadata)
if err != nil {
conn.Conn().Close()
return
}
relay(remote, conn.Conn())
}()
}
}()
//创建netflix.txt
f, err := os.OpenFile(exPath+"/netflix.txt", os.O_CREATE|os.O_TRUNC|os.O_WRONLY, 0666)
defer f.Close()
if err != nil {
fmt.Println("新建netflix.txt失败:", err)
}
//创建excel
excel := excelize.NewFile()
excel.SetCellValue("Sheet1", "A1", "节点名")
excel.SetCellValue("Sheet1", "B1", "ip地址")
excel.SetCellValue("Sheet1", "C1", "复用次数")
excel.SetCellValue("Sheet1", "D1", "是否解锁")
excel.SetCellValue("Sheet1", "E1", "详细说明")
index := 1
nodes := config.Proxies
for node, server := range nodes {
if server.Type() != constant.Shadowsocks && server.Type() != constant.ShadowsocksR && server.Type() != constant.Snell && server.Type() != constant.Socks5 && server.Type() != constant.Http && server.Type() != constant.Vmess && server.Type() != constant.Trojan {
continue
}
proxy = server
//落地机IP
ip := getIP()
str := fmt.Sprintf("%d 节点名: %s ip地址:%s\n", index, node, ip)
fmt.Print(str)
//Netflix检测
ok, out := nf.NF("http://" + proxyUrl)
if out == "" {
out = "完全不支持Netflix"
}
fmt.Println(out)
fmt.Fprintln(f, enc.ConvertString(str+out))
excel.SetCellValue("Sheet1", "A"+strconv.Itoa(index+1), node)
excel.SetCellValue("Sheet1", "B"+strconv.Itoa(index+1), ip)
if ip != "" {
excel.SetCellFormula("Sheet1", "C"+strconv.Itoa(index+1), "= COUNTIF(B:B,B"+strconv.Itoa(index+1)+")")
}
excel.SetCellValue("Sheet1", "D"+strconv.Itoa(index+1), ok)
excel.SetCellValue("Sheet1", "E"+strconv.Itoa(index+1), out)
index++
}
if err := excel.SaveAs(exPath+"/Netflix.xlsx"); err != nil {
fmt.Println(err)
}
}