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.
35 lines
645 B
35 lines
645 B
2 weeks ago
|
package socks5
|
||
|
|
||
|
import (
|
||
|
"net"
|
||
|
"time"
|
||
|
)
|
||
|
|
||
|
// DirectDialer 直接连接拨号器
|
||
|
type DirectDialer struct {
|
||
|
timeout time.Duration
|
||
|
}
|
||
|
|
||
|
// Dial 建立连接
|
||
|
func (d *DirectDialer) Dial(network, address string) (net.Conn, error) {
|
||
|
if d.timeout > 0 {
|
||
|
return net.DialTimeout(network, address, d.timeout)
|
||
|
}
|
||
|
return net.Dial(network, address)
|
||
|
}
|
||
|
|
||
|
// DirectResolver 直接DNS解析器
|
||
|
type DirectResolver struct{}
|
||
|
|
||
|
// Resolve 解析域名
|
||
|
func (r *DirectResolver) Resolve(domain string) (net.IP, error) {
|
||
|
ips, err := net.LookupIP(domain)
|
||
|
if err != nil {
|
||
|
return nil, err
|
||
|
}
|
||
|
if len(ips) == 0 {
|
||
|
return nil, net.ErrClosed
|
||
|
}
|
||
|
return ips[0], nil
|
||
|
}
|