要进行测试 H.323 呼叫,您无法击败 ohphone:
(sleep 30; echo q) | ohphone -s Default -n -u from_user to_user@gateway > /tmp/output.$$
你通常可以在你的 linux 发行版中找到 ohphone 作为一个包:
apt-get install ohphone
可以在voxgratia上找到源代码
虽然较旧,但它仍然可以出色地工作。
使用 ohphone 处理输出有点棘手,但您可以使用 perl 脚本之类的东西将其处理为 errno 值。
这是一个快速而肮脏的示例:
#!/usr/bin/env perl
$delay=$ARGV[0];
if(! $delay) { $delay = 10; }
$from=$ARGV[1];
if(! $from) { $from = "default_from_user"; }
$to=$ARGV[2];
if(! $to) { $to = "default_to_user"; }
$gateway=$ARGV[3];
if(! $gateway) { $gateway = "127.0.0.1"; }
print "Running: (sleep $delay; echo q ) | (ohphone -s Default -n -u $from $to\@$gateway)|\n";
open(IN,"(sleep $delay; echo q ) | (ohphone -s Default -n -u $from $to\@$gateway)|");
my $call_started=false;
my $call_completed=false;
my @results;
my $skip=1;
while($line=<IN>) {
if($line=~/Listening interfaces/) {
$skip=0;
next;
}
if($skip) {
next;
}
if($line=~/^Could not open sound device/) {
next;
}
chomp($line);
push(@results,$line);
if($line=~/was busy$/) {
print "$to: Called party busy\n";
exit 1;
}
if($line=~/^Call with .* completed, duration (.*)$/) {
print "$to: Completed duration $1 call.\n";
exit 0;
}
if($line=~/has cleared the call, duration (.*)$/) {
print "$to: Completed duration $1 call.\n";
exit 0;
}
if($line=~/^Call with .* completed$/) {
print "$to: No call duration.\n";
exit 2;
}
}
close(IN);
$result=join("\n",@results);
print "$ARGV[0]: Unknown results:\n$result\n";
exit 255;
这个脚本已经有好几年的历史了,但在那段时间里它对我们来说效果很好。