Applescript 中的 shell 输出
我想知道如何从 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
以上是完整的 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"
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"