如何检查MacOS终端中是否有internet连接?
我使用了Ping命令:如何检查MacOS终端中是否有internet连接?,macos,terminal,ping,extendscript,ecmascript-3,Macos,Terminal,Ping,Extendscript,Ecmascript 3,我使用了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
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
如果您在MacOS终端上,您可以通过以下方式检查internet连接:
nc -z www.google.com 80
这也需要几秒钟——可以设置超时吗?我想试试-G。