我在powershell中有20个curl
命令。我创建了一个循环来连续运行它们。当命令响应太长可能是错误时,我想跳过其他命令继续。
$i = 1
while($true){
write-Progress -activity "SCAN" -status "ROUND $i"
write-host "++++++++++++++++++++++++++++++++++++ ROUND $i +++++++++++++++++++++++++++++++++++++++++" -foregroundcolor "red" -backgroundcolor "white"
curl 10.0.119.61:8101
write-host =============================>>10.0.119.61:8101<<============================= -foregroundcolor "darkgreen" -backgroundcolor "yellow"
curl 10.0.119.61:8101
write-host =============================>>10.0.119.61:8102<<============================= -foregroundcolor "darkgreen" -backgroundcolor "yellow"
curl 10.0.119.61:8102
write-host =============================>>10.0.119.62:8201<<============================= -foregroundcolor "darkgreen" -backgroundcolor "yellow"
curl 10.0.119.62:8201
write-host =============================>>10.0.119.62:8202<<============================= -foregroundcolor "darkgreen" -backgroundcolor "yellow"
curl 10.0.119.62:8202
write-host =============================>>10.0.119.63:8301<<============================= -foregroundcolor "darkgreen" -backgroundcolor "yellow"
curl 10.0.119.63:8301
write-host =============================>>10.0.119.63:8302<<============================= -foregroundcolor "darkgreen" -backgroundcolor "yellow"
curl 10.0.119.63:8302
write-host =============================>>10.0.119.64:8401<<============================= -foregroundcolor "darkgreen" -backgroundcolor "yellow"
curl 10.0.119.64:8401
write-host =============================>>10.0.119.64:8402<<============================= -foregroundcolor "darkgreen" -backgroundcolor "yellow"
curl 10.0.119.64:8402
write-host =============================>>10.0.119.65:8501<<============================= -foregroundcolor "darkgreen" -backgroundcolor "yellow"
curl 10.0.119.65:8501
write-host =============================>>10.0.119.65:8502<<============================= -foregroundcolor "darkgreen" -backgroundcolor "yellow"
curl 10.0.119.65:8502
write-host =============================>>10.0.119.66:8601<<============================= -foregroundcolor "darkgreen" -backgroundcolor "yellow"
curl 10.0.119.66:8601
write-host =============================>>10.0.119.66:8602<<============================= -foregroundcolor "darkgreen" -backgroundcolor "yellow"
curl 10.0.119.66:8602
write-host =============================>>10.0.119.67:8701<<============================= -foregroundcolor "darkgreen" -backgroundcolor "yellow"
curl 10.0.119.67:8701
write-host =============================>>10.0.119.67:8702<<============================= -foregroundcolor "darkgreen" -backgroundcolor "yellow"
curl 10.0.119.67:8702
write-host =============================>>10.0.119.68:8801<<============================= -foregroundcolor "darkgreen" -backgroundcolor "yellow"
curl 10.0.119.68:8801
write-host =============================>>10.0.119.68:8802<<============================= -foregroundcolor "darkgreen" -backgroundcolor "yellow"
curl 10.0.119.68:8802
write-host =============================>>10.0.119.69:8901<<============================= -foregroundcolor "darkgreen" -backgroundcolor "yellow"
curl 10.0.119.69:8901
write-host =============================>>10.0.119.69:8902<<============================= -foregroundcolor "darkgreen" -backgroundcolor "yellow"
curl 10.0.119.69:8902
write-host =============================>>10.0.119.70:9001<<============================= -foregroundcolor "darkgreen" -backgroundcolor "yellow"
curl 10.0.119.70:9001
write-host =============================>>10.0.119.70:9002<<============================= -foregroundcolor "darkgreen" -backgroundcolor "yellow"
curl 10.0.119.70:9002
sleep 5
$i++
if ($i % 10 -eq 0){
clear
$i++
}}
答案 0 :(得分:0)
如果curl
表示默认别名 Invoke-Webrequest
,请使用 -TimeoutSec
-TimeoutSec
指定请求在超时之前可以等待的时间。
以秒为单位输入值。默认值0指定 无限期超时。
即:
Invoke-WebRequest -TimeoutSec 30 "http://address.com/"
将设置30秒超时
Sidenote 在实际cURL
中执行此操作:
--connect-timeout
&lt; seconds&gt;