-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
53 lines (44 loc) · 1.38 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
package main
import (
"flag"
"log"
"github.com/txthinking/socks5"
)
const defaultProxyURL = "socks.pr.oxylabs.io:7777"
const defaultProxyUsername = "customer-USERNAME"
const defaultProxyPassword = "PASSWORD"
const defaultTarget = "echo-udp.oxylabs.io:42000"
const defaultContent = "Hello UDP!"
func SOCKS5UDPRequest(proxyAddress, proxyUsername, proxyPassword string, target string, payload string) (string, error) {
client, err := socks5.NewClient(proxyAddress, proxyUsername, proxyPassword, 10, 10)
if err != nil {
return "", err
}
conn, err := client.Dial("udp", target)
if err != nil {
return "", err
}
_, err = conn.Write([]byte(payload))
if err != nil {
return "", err
}
buf := make([]byte, 2048)
n, err := conn.Read(buf)
if err != nil {
return "", err
}
return string(buf[:n]), nil
}
func main() {
proxyUrl := flag.String("proxy", defaultProxyURL, "proxy URL (hostname:port")
proxyUsername := flag.String("u", defaultProxyUsername, "proxy username")
proxyPassword := flag.String("p", defaultProxyPassword, "proxy password")
target := flag.String("t", defaultTarget, "target (hostname:port)")
content := flag.String("c", defaultContent, "content to send to target")
flag.Parse()
res, err := SOCKS5UDPRequest(*proxyUrl, *proxyUsername, *proxyPassword, *target, *content)
if err != nil {
log.Fatalln("Request failed due to: ", err)
}
log.Println("Response: ", res)
}