Applescript 中的 shell 输出

Fat*_*oth 1 ip applescript ping

我想知道如何从 Applescript 中 shell 命令的输出中仅提取某些数据。我希望能够仅通过“ping -o”命令将 IP 地址传递到变量中,如下所示:

   do shell script "ping -o " & blockedURL

    -- Set the IP to blockedIP -- 

    set blockedIP to ..
Run Code Online (Sandbox Code Playgroud)

但我收到这个:

“PING example.com (192.0.43.10):来自 192.0.43.10 的 56 个数据字节 64 个字节:icmp_seq=0 ttl=239 time=101.587 ms

--- example.com ping 统计数据 --- 发送 1 个数据包,接收 1 个数据包,往返 0.0% 数据包丢失 min/avg/max/stddev = 101.587/101.587/101.587/0.000 ms"

当我执行 ping 命令时,我收到了大量不需要的数据。有什么办法可以只回忆起吗(192.0.43.10)

Kas*_*sel 5

set a to "PING example.com (192.0.43.10): 56 data bytes 64 bytes from 192.0.43.10: icmp_seq=0 ttl=239 time=101.587 ms

--- example.com ping statistics --- 1 packets transmitted, 1 packets received, 0.0% packet loss round-trip min/avg/max/stddev = 101.587/101.587/101.587/0.000 ms"

set text item delimiters to "("
set temp to text item 2 of a
set text item delimiters to ")"
set temp to first text item of temp
return temp
Run Code Online (Sandbox Code Playgroud)

以上是完整的 applescript 解决方案。您还可以使用以下命令仅使用 shell 来获取 IP,ping -o www.google.com | cut -d'(' -f2|cut -d')' -f1 | head -n1因此在 applescript 中它看起来像这样: do shell script "ping -o " & blockedURL & " | cut -d'(' -f2 | cut -d')' -f1 | head -n1"