使用php获取traceroute跃点列表 [英] Get list of traceroute hops with php
问题描述
shell_exec("traceroute IPaddress)
返回traceroute to IPaddress (IPaddress), 30 hops max, 40 byte packets
我如何检索实际的啤酒花列表,以便知道发生问题的地方?
How do I retrieve the actual list of hops so I can tell where a problem occurs?
推荐答案
应该将这些消息写到stderr
而不是常规的stdout
,所以我不太确定为什么会看到它们在输出中.
Those messages are supposed to be written to stderr
instead of the regular stdout
, so I'm not too sure why you're seeing them appear in the output.
我建议使用exec()
而不是shell_exec()
,因为它可以捕获过程的输出和返回码:
Instead of shell_exec()
I would recommend using exec()
because it captures both the output AND the return code of the process:
exec('traceroute example.com 2>&1', $out, $code);
if ($code) {
die("An error occurred while trying to traceroute: " . join("\n", $out);
}
print_r($out);
要稍微加快该命令的速度,可以在运行traceroute
时使用-n
选项,以避免不必对中间跃点进行DNS查找.
To speed up the command a little you could use the -n
option when you run traceroute
to avoid having to do DNS lookups for the intermediate hops.
请注意,运行traceroute
可能需要一段时间;如果在命令行上运行它,有时可能会看到其中包含* * *
的行,这可能需要很长时间!
Note that running traceroute
can take a while; if you run it on the command line you can sometimes see lines with * * *
in them, which can take ages!
这篇关于使用php获取traceroute跃点列表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!