Skip to content

Commit

Permalink
添加不正确的输入处理办法
Browse files Browse the repository at this point in the history
  • Loading branch information
damit5 committed Jul 18, 2022
1 parent 6b9bc13 commit 79e97e8
Showing 1 changed file with 14 additions and 6 deletions.
20 changes: 14 additions & 6 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,13 +29,21 @@ var threads int
func checkCDN(domain string) {
defer semaphore.Done()
// 域名处理,可能传入是URL
if strings.Contains(domain, "://") {
parse, err := url.Parse(domain)
if err != nil {
return
}
domain = parse.Hostname()
/*
非正常格式:需要先变成标准格式 www.baidu.com
https://www.baidu.com
1.2.3.4:80
www.baidu.com:443
*/
if !strings.HasPrefix(domain, "http") {
domain = "http://" + domain
}

parse, err := url.Parse(domain)
if err != nil {
return
}
domain = parse.Hostname()

// 域名解析成IP,可能有多个IP
ips, err := net.LookupIP(domain)
Expand Down

0 comments on commit 79e97e8

Please sign in to comment.