fix: http sniffer skip ip
This commit is contained in:
parent
4611fbfe0c
commit
835cab58cf
1 changed files with 21 additions and 1 deletions
|
@ -3,6 +3,7 @@ package sniffer
|
||||||
import (
|
import (
|
||||||
"bytes"
|
"bytes"
|
||||||
"errors"
|
"errors"
|
||||||
|
"fmt"
|
||||||
C "github.com/Dreamacro/clash/constant"
|
C "github.com/Dreamacro/clash/constant"
|
||||||
"net"
|
"net"
|
||||||
"strings"
|
"strings"
|
||||||
|
@ -88,13 +89,32 @@ func SniffHTTP(b []byte) (*string, error) {
|
||||||
host, _, err := net.SplitHostPort(rawHost)
|
host, _, err := net.SplitHostPort(rawHost)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
if addrError, ok := err.(*net.AddrError); ok && strings.Contains(addrError.Err, "missing port") {
|
if addrError, ok := err.(*net.AddrError); ok && strings.Contains(addrError.Err, "missing port") {
|
||||||
host = rawHost
|
return parseHost(rawHost)
|
||||||
} else {
|
} else {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if net.ParseIP(host) != nil {
|
||||||
|
return nil, fmt.Errorf("host is ip")
|
||||||
|
}
|
||||||
|
|
||||||
return &host, nil
|
return &host, nil
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return nil, ErrNoClue
|
return nil, ErrNoClue
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func parseHost(host string) (*string, error) {
|
||||||
|
if strings.HasPrefix(host, "[") && strings.HasSuffix(host, "]") {
|
||||||
|
if net.ParseIP(host[1:len(host)-1]) != nil {
|
||||||
|
return nil, fmt.Errorf("host is ip")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if net.ParseIP(host) != nil {
|
||||||
|
return nil, fmt.Errorf("host is ip")
|
||||||
|
}
|
||||||
|
|
||||||
|
return &host, nil
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in a new issue