-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathadd.go
73 lines (70 loc) · 1.79 KB
/
add.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
package main
import (
"encoding/json"
"github.com/phuslu/iploc"
"log"
"net"
"net/http"
"net/url"
"os"
"strings"
"time"
)
const (
up = "0"
down = "0"
total = "0"
remark = ""
enable = "true"
expiryTime = "0"
listen = ""
protocol = "dokodemo-door"
streamSettings = `{
"network": "tcp",
"security": "none",
"tcpSettings": {
"header": {
"type": "none"
}
}
}`
sniffing = "{}"
)
func addProxy(ip string, session *http.Cookie, of *os.File, remoteAddress string, remotePort string) {
settings := `{
"address": "` + remoteAddress + `",
"port": ` + remotePort + `,
"network": "tcp,udp"
}`
port := remotePort
endpoint := "http://" + ip + ":54321/xui/inbound/add"
client := http.Client{
Timeout: 5 * time.Second,
}
payload := "up=" + up + "&down=" + down + "&total=" + total + "&remark=" + remark + "&enable=" + enable + "&expiryTime=" + expiryTime + "&listen=" + listen + "&port=" + port + "&protocol=" + protocol + "&settings=" + url.QueryEscape(settings) + "&streamSettings=" + url.QueryEscape(streamSettings) + "&sniffing=" + url.QueryEscape(sniffing)
var data = strings.NewReader(payload)
req, err := http.NewRequest("POST", endpoint, data)
if err != nil {
log.Println("Could not compose request: ", err)
}
req.AddCookie(session)
req.Header.Set("Content-Type", "application/x-www-form-urlencoded; charset=UTF-8")
resp, err := client.Do(req)
if err != nil {
log.Fatal(err)
}
defer resp.Body.Close()
input := new(xResponse)
err = json.NewDecoder(resp.Body).Decode(input)
if input.Success {
log.Println("[Success]", ip, iploc.Country(net.ParseIP(ip)))
_, err := of.WriteString(ip + "\n")
if err != nil {
log.Panicln(err)
}
err = of.Sync()
if err != nil {
log.Panicln(err)
}
}
}