我们使用这个 curl 命令(Windows 10)来检查 URls 的连接状态:
curl -v https://techdocs.broadcom.com 2>> C:\Temp\ResultadaoURL.txt
,结果如下:
* Trying 104.18.32.150:443...
* Connected to techdocs.broadcom.com (104.18.32.150) port 443 (#0)
* schannel: disabled automatic use of client certificate
* ALPN: offers http/1.1
* ALPN: server accepted http/1.1
> GET / HTTP/1.1
> Host: techdocs.broadcom.com
> User-Agent: curl/7.83.1
> Accept: */*
>
* Mark bundle as not supporting multiuse
< HTTP/1.1 200 OK
< Date: Mon, 16 Jan 2023 07:06:43 GMT
< Content-Type: text/html;charset=utf-8
< Transfer-Encoding: chunked
< Connection: keep-alive
< Access-Control-Allow-Origin: *
< Cache-control: no-cache="set-cookie"
我们只需要打印输出第二行“* 连接到 techdocs.broadcom.com (104.18.32.150) 端口 443 (#0)”,是否有任何针对此特定数据的变量或任何命令指令?
例如此命令仅打印 response_code:
curl -o responseFile.html http://www.somewhere.com -w "%{response_code};%{time_total}" > dataFile.txt 2> informationFile.txt
答案1
这curl 手册页 似乎没有为“连接到”字段提供变量。
但用另一种方法做应该很简单:
Linux:
curl -v https://techdocs.broadcom.com | grep 'Connected to' >> C:\Temp\ResultadaoURL.txt
窗户:
curl -v https://techdocs.broadcom.com | findstr "Connected to" >> C:\Temp\ResultadaoURL.txt