Applescript 中的 shell 输出

发布于 2024-12-17 07:47:33 字数 581 浏览 0 评论 0原文

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

   do shell script "ping -o " & blockedURL

    -- Set the IP to blockedIP -- 

    set blockedIP to ..

但我收到以下消息:

“PING example.com (192.0.43.10):56 个数据字节 64 个字节来自 192.0.43.10:icmp_seq=0 ttl=239 时间=101.587 毫秒

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

当我执行 ping 命令时,我收到了很多不需要的数据。有什么方法可以只调用 (192.0.43.10) 吗?

I was wondering how to extract only certain data from the output of a shell command in Applescript. I want to be able to only pass the IP address into the variable from a "ping -o" command like this:

   do shell script "ping -o " & blockedURL

    -- Set the IP to blockedIP -- 

    set blockedIP to ..

but I receive this:

"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"

When I execute the ping command I receive a lot of data I dont need. Is there any way of being able to only recall the (192.0.43.10)?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

樱花坊 2024-12-24 07:47:33
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

以上是完整的 applescript 解决方案。您还可以使用以下命令仅使用 shell 来获取 IP ping -o www.google.com |剪切-d'('-f2|剪切-d')'-f1 | head -n1 所以在 applescript 中它看起来像这样:
执行 shell 脚本“ping -o” &被阻止的URL & " | cut -d'(' -f2 | cut -d')' -f1 | head -n1"

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

The above is a full applescript solution. You can also use the following to get the IP just using the shell ping -o www.google.com | cut -d'(' -f2|cut -d')' -f1 | head -n1 so in applescript it would look like this :
do shell script "ping -o " & blockedURL & " | cut -d'(' -f2 | cut -d')' -f1 | head -n1"

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文