Menu

[r10]: / trunk / examples / ping.php  Maximize  Restore  History

Download this file

49 lines (38 with data), 1.1 kB

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
#!/usr/local/bin/php -q
<?php
set_time_limit(0);
require('phpagi.php');
$agi = new AGI();
$agi->answer();
// Play the "Enter the host you wish to ping, followed by the pound sign" prompt
// and then play the beep.
$agi->stream_file('ping');
$result = $agi->get_data('beep', 3000, 20);
$ip = str_replace('*', '.', $result['result']);
/* Danger Will Robinson! This does NOT properly escape the ping command!
* Someone could subvert your system if you don't fix this! - NO WARRANTY :P */
$execstr = "/bin/ping -c 5 -q -w 9 $ip|grep transmitted";
// be polite.
$agi->stream_file('thanks', '#');
$p = popen($execstr, 'r');
if($p == FALSE)
{
$agi->text2wav("Failed to ping $ip");
$agi->conlog("Failed to ping $execstr");
}
else
{
$str = '';
while(!feof($p))
{
$r = fgets($p, 1024);
if(!$r) break;
$str .= $r;
}
// a minor hack.
$str = str_replace('ms', 'milli-seconds', $str);
// have festival read back the ping results.
$agi->text2wav("$ip - $str");
}
$agi->hangup();
?>
Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.