我使用了 Ping命令:
ping -c1 -W1 8.8.8.8
如果在线效果很好,但如果互联网不可用或 LAN 关闭,终端需要很长时间才能回复结果..
我希望终端在最长 1 秒或 0.5 秒内回复以使用结果
扩展脚本代码:
var command = "ping -c1 -W1 8.8.8.8";
var result= system.callSystem(command);
我尝试使用 -t 或 -W 设置超时但失败了
编辑:
感谢 Philippe,解决方案是:
nc -z www.google.com 80 -G1