MCPcopy
hub / github.com/pingc0y/URLFinder / GetHost

Function GetHost

util/utils.go:152–184  ·  view source on GitHub ↗

提取顶级域名

(u string)

Source from the content-addressed store, hash-verified

150
151// 提取顶级域名
152func GetHost(u string) string {
153 re := regexp.MustCompile("([a-z0-9\\-]+\\.)*([a-z0-9\\-]+\\.[a-z0-9\\-]+)(:[0-9]+)?")
154 var host string
155 hosts := re.FindAllString(u, 1)
156 if len(hosts) == 0 {
157 host = u
158 } else {
159 host = hosts[0]
160 }
161 re2 := regexp.MustCompile("[^.]*?\\.[^.,^:]*")
162 host2 := re2.FindAllString(host, -1)
163 re3 := regexp.MustCompile("(([01]?[0-9]{1,3}|2[0-4][0-9]|25[0-5])\\.){3}([01]?[0-9]{1,3}|2[0-4][0-9]|25[0-5])")
164 hostIp := re3.FindAllString(u, -1)
165 if len(hostIp) == 0 {
166 if len(host2) == 1 {
167 host = host2[0]
168 } else {
169 re3 := regexp.MustCompile("\\.[^.]*?\\.[^.,^:]*")
170 var ho string
171 hos := re3.FindAllString(host, -1)
172
173 if len(hos) == 0 {
174 ho = u
175 } else {
176 ho = hos[len(hos)-1]
177 }
178 host = strings.Replace(ho, ".", "", 1)
179 }
180 } else {
181 return hostIp[0]
182 }
183 return host
184}
185
186// 去重+去除错误url
187func RemoveRepeatElement(list []mode.Link) []mode.Link {

Callers 4

OutFileCsvFunction · 0.92
OutFileJsonFunction · 0.92
OutFileHtmlFunction · 0.92
PrintFunction · 0.92

Calls

no outgoing calls

Tested by

no test coverage detected