| 1 | package socks5scip-go gomod github.com/txthinking/socks5 . `github.com/txthinking/socks5`/ |
| 2 | |
| 3 | import ( |
| 4 | "ioscip-go gomod github.com/golang/go/src go1.16 io/" |
| 5 | "logscip-go gomod github.com/golang/go/src go1.16 log/" |
| 6 | "netscip-go gomod github.com/golang/go/src go1.16 net/" |
| 7 | ) |
| 8 | |
| 9 | // Connect remote conn which u want to connect with your dialer |
| 10 | // Error or OK both replied. |
| 11 | func (r *Requestscip-go gomod github.com/txthinking/socks5 . `github.com/txthinking/socks5`/Request#) Connectscip-go gomod github.com/txthinking/socks5 . `github.com/txthinking/socks5`/Request#Connect().(w ioscip-go gomod github.com/golang/go/src go1.16 io/.Writerscip-go gomod github.com/golang/go/src go1.16 io/Writer#) (netscip-go gomod github.com/golang/go/src go1.16 net/.Connscip-go gomod github.com/golang/go/src go1.16 net/Conn#, error) { |
| 12 | if Debugscip-go gomod github.com/txthinking/socks5 . `github.com/txthinking/socks5`/Debug. { |
| 13 | logscip-go gomod github.com/golang/go/src go1.16 log/.Printlnscip-go gomod github.com/golang/go/src go1.16 log/Println().("Call:", r.Addressscip-go gomod github.com/txthinking/socks5 . `github.com/txthinking/socks5`/Request#Address().()) |
| 14 | } |
| 15 | rc, err := DialTCPscip-go gomod github.com/txthinking/socks5 . `github.com/txthinking/socks5`/DialTCP.("tcp", "", r.Addressscip-go gomod github.com/txthinking/socks5 . `github.com/txthinking/socks5`/Request#Address().()) |
| 16 | if err != nil { |
| 17 | var p *Replyscip-go gomod github.com/txthinking/socks5 . `github.com/txthinking/socks5`/Reply# |
| 18 | if r.Atypscip-go gomod github.com/txthinking/socks5 . `github.com/txthinking/socks5`/Request#Atyp. == ATYPIPv4scip-go gomod github.com/txthinking/socks5 . `github.com/txthinking/socks5`/ATYPIPv4. || r.Atypscip-go gomod github.com/txthinking/socks5 . `github.com/txthinking/socks5`/Request#Atyp. == ATYPDomainscip-go gomod github.com/txthinking/socks5 . `github.com/txthinking/socks5`/ATYPDomain. { |
| 19 | p = NewReplyscip-go gomod github.com/txthinking/socks5 . `github.com/txthinking/socks5`/NewReply().(RepHostUnreachablescip-go gomod github.com/txthinking/socks5 . `github.com/txthinking/socks5`/RepHostUnreachable., ATYPIPv4scip-go gomod github.com/txthinking/socks5 . `github.com/txthinking/socks5`/ATYPIPv4., []byte{0x00, 0x00, 0x00, 0x00}, []byte{0x00, 0x00}) |
| 20 | } else { |
| 21 | p = NewReplyscip-go gomod github.com/txthinking/socks5 . `github.com/txthinking/socks5`/NewReply().(RepHostUnreachablescip-go gomod github.com/txthinking/socks5 . `github.com/txthinking/socks5`/RepHostUnreachable., ATYPIPv6scip-go gomod github.com/txthinking/socks5 . `github.com/txthinking/socks5`/ATYPIPv6., []byte(netscip-go gomod github.com/golang/go/src go1.16 net/.IPv6zeroscip-go gomod github.com/golang/go/src go1.16 net/IPv6zero.), []byte{0x00, 0x00}) |
| 22 | } |
| 23 | if _, err := p.WriteToscip-go gomod github.com/txthinking/socks5 . `github.com/txthinking/socks5`/Reply#WriteTo().(w); err != nil { |
| 24 | return nil, err |
| 25 | } |
| 26 | return nil, err |
| 27 | } |
| 28 | |
| 29 | a, addr, port, err := ParseAddressscip-go gomod github.com/txthinking/socks5 . `github.com/txthinking/socks5`/ParseAddress().(rc.LocalAddrscip-go gomod github.com/golang/go/src go1.16 net/Conn#LocalAddr().().Stringscip-go gomod github.com/golang/go/src go1.16 net/Addr#String().()) |
| 30 | if err != nil { |
| 31 | rc.Closescip-go gomod github.com/golang/go/src go1.16 net/Conn#Close().() |
| 32 | var p *Replyscip-go gomod github.com/txthinking/socks5 . `github.com/txthinking/socks5`/Reply# |
| 33 | if r.Atypscip-go gomod github.com/txthinking/socks5 . `github.com/txthinking/socks5`/Request#Atyp. == ATYPIPv4scip-go gomod github.com/txthinking/socks5 . `github.com/txthinking/socks5`/ATYPIPv4. || r.Atypscip-go gomod github.com/txthinking/socks5 . `github.com/txthinking/socks5`/Request#Atyp. == ATYPDomainscip-go gomod github.com/txthinking/socks5 . `github.com/txthinking/socks5`/ATYPDomain. { |
| 34 | p = NewReplyscip-go gomod github.com/txthinking/socks5 . `github.com/txthinking/socks5`/NewReply().(RepHostUnreachablescip-go gomod github.com/txthinking/socks5 . `github.com/txthinking/socks5`/RepHostUnreachable., ATYPIPv4scip-go gomod github.com/txthinking/socks5 . `github.com/txthinking/socks5`/ATYPIPv4., []byte{0x00, 0x00, 0x00, 0x00}, []byte{0x00, 0x00}) |
| 35 | } else { |
| 36 | p = NewReplyscip-go gomod github.com/txthinking/socks5 . `github.com/txthinking/socks5`/NewReply().(RepHostUnreachablescip-go gomod github.com/txthinking/socks5 . `github.com/txthinking/socks5`/RepHostUnreachable., ATYPIPv6scip-go gomod github.com/txthinking/socks5 . `github.com/txthinking/socks5`/ATYPIPv6., []byte(netscip-go gomod github.com/golang/go/src go1.16 net/.IPv6zeroscip-go gomod github.com/golang/go/src go1.16 net/IPv6zero.), []byte{0x00, 0x00}) |
| 37 | } |
| 38 | if _, err := p.WriteToscip-go gomod github.com/txthinking/socks5 . `github.com/txthinking/socks5`/Reply#WriteTo().(w); err != nil { |
| 39 | return nil, err |
| 40 | } |
| 41 | return nil, err |
| 42 | } |
| 43 | if a == ATYPDomainscip-go gomod github.com/txthinking/socks5 . `github.com/txthinking/socks5`/ATYPDomain. { |
| 44 | addr = addr[1:] |
| 45 | } |
| 46 | p := NewReplyscip-go gomod github.com/txthinking/socks5 . `github.com/txthinking/socks5`/NewReply().(RepSuccessscip-go gomod github.com/txthinking/socks5 . `github.com/txthinking/socks5`/RepSuccess., a, addr, port) |
| 47 | if _, err := p.WriteToscip-go gomod github.com/txthinking/socks5 . `github.com/txthinking/socks5`/Reply#WriteTo().(w); err != nil { |
| 48 | rc.Closescip-go gomod github.com/golang/go/src go1.16 net/Conn#Close().() |
| 49 | return nil, err |
| 50 | } |
| 51 | |
| 52 | return rc, nil |
| 53 | } |