-2

我使用了 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
4

1 回答 1

2

如果您在 MacOS 终端上,您可以通过以下方式检查互联网连接:

nc -z www.google.com 80
于 2020-03-14T13:02:30.980 回答