curl 将所有域名转换为相同格式的可靠方法

rslzwgfq  于 2022-11-13  发布在  其他
关注(0)|答案(1)|浏览(123)

我正在处理一个包含大约10亿个不同网站的数据库。问题是它包含了各种不同的拼写:

example.com
subdomain.example.com
http://example.com
https://example.com
https://example.com/
https://sub.example.com
...

此外,一些域已过时,并具有永久重定向。
我该怎么收拾这烂摊子?
我正在使用curl {domain} -s -L -I -o /dev/null -w '%{url_effective}'来获得有效的网址,结果是有希望的。
我注意到的一些问题:
1.有些域可能有curl无法解析的基于JS的重定向。太少了。
1.当http和https协议都可用时,它返回http一。将https优先化会很好。
1.非域字符串也会被解析,例如curl notadomain -s -L -I -o /dev/null -w '%{url_effective}'http://notadomain/。如果curl在这种情况下抛出错误会更好。
如何解决以上问题?尤其是最后一个问题。
这个解决方案还有什么我现在看不到的缺点吗?
我的另一个想法是解析每个域后面的服务器IP。

gtlvzcf8

gtlvzcf81#

这个解决方案还有什么我现在看不到的缺点吗?
如果不知道你在做什么,为什么要这么做,我就不能很好地回答这个问题。
curl不需要抛出错误。
但它确实给予了你足够的信息,让你自己做出决定。
这些是返回的curl值。

content_type
http_code
header_size
request_size
filetime
ssl_verify_result
redirect_count
total_time
namelookup_time
connect_time
pretransfer_time
size_upload
size_download
speed_download
speed_upload
download_content_length
upload_content_length
starttransfer_time
redirect_time
redirect_url
primary_ip
certinfo
request_header
response_headers

这些是重定向到HTTPS的HTTP请求的典型值

content_type = text/html; charset=UTF-8
http_code = 200
header_size = 342
request_size = 98
filetime = -1
ssl_verify_result = 20
redirect_count = 1
total_time = 0.202927
namelookup_time = 0.000971
connect_time = 0.059346
pretransfer_time = 0.094196
size_upload = 0.0
size_download = 4753.0
speed_download = 23422.0
speed_upload = 0.0
download_content_length = -1.0
upload_content_length = 0.0
starttransfer_time = 0.199499
redirect_time = 0.060231
redirect_url = 
primary_ip = 99.999.999.999
certinfo = primary_port = 443,  local_ip = 88.888.888.888, local_port = 55530,

HTTP/1.1 301 Moved Permanently
Date: Fri, 21 Oct 2022 00:44:18 GMT
Server: Apache
Location: https://example.com/
Content-Length: 227
Content-Type: text/html; charset=iso-8859-1

HTTP/1.1 200 OK
Date: Fri, 21 Oct 2022 00:44:18 GMT
Server: Apache
Vary: User-Agent
Transfer-Encoding: chunked
Content-Type: text/html; charset=UTF-8

这与没有DNS的url完全不同

content_type = NULL
http_code = 0
header_size = 0
request_size = 0
filetime = -1
ssl_verify_result = 0
redirect_count = 0
total_time = 0.221879
namelookup_time = 0.0
connect_time = 0.0
pretransfer_time = 0.0
size_upload = 0.0
size_download = 0.0
speed_download = 0.0
speed_upload = 0.0
download_content_length = -1.0
upload_content_length = -1.0
starttransfer_time = 0.0
redirect_time = 0.0
redirect_url = 
primary_ip = 
certinfo = primary_port = 0, local_ip = , local_port = 0

相关问题