Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/cassandra/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何检查MacOS终端中是否有internet连接?_Macos_Terminal_Ping_Extendscript_Ecmascript 3 - Fatal编程技术网

如何检查MacOS终端中是否有internet连接?

如何检查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命令:

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。