Example #1
0
#!/usr/bin/env php
<?php 
require '../../Classes/iax_call.class.php';
require '../../Classes/iax_decode.class.php';
if ($argc < 2) {
    die("Usage: originate iax://user:pass@host/from_number/to_number?caller_id\n");
}
// get data
extract(parse_url($argv[1]));
// from and to numbers
$from_to = array_filter(split('/', $path));
// initiate iax class
$call = new IaxCall($host, '4569', $user, $pass);
// originate a call
$response = $call->originate(@$query, reset($from_to));
// load packet response into decoder
$i = new IAX_Decode();
$i->load($response);
// handle a challenge if it exists
if ($i->messagetype == 'auth_challenge') {
    $call->callno_far = $i->fields['scalli'];
    $call->seq_in = $i->fields['iseqid'];
    $call->respondChallenge($i->data['challenge_data']);
    $success = true;
}
// wait for accept or reject
while (!in_array($i->messagetype, array('accept', 'reject'))) {
    $i->load($call->result());
}
// if call accepted, wait for answer
if ($i->messagetype == 'accept') {
Example #2
0
require '../../Classes/iax_call.class.php';
require '../../Classes/iax_decode.class.php';
// host to ping
$host = @$argv[1];
if (!$host) {
    die("Usage: iaxping hostname [count] [interval (ms)]\n");
}
$packets = @$argv[2] ? $argv[2] : 4;
$delay = @$argv[3] ? $argv[3] : 1000;
//ms
// init decoder
$frame = new IAX_Decode();
// ping loop
for ($n = 1; $n <= $packets; $n++) {
    // init, die on host res fail, etc
    $call = new IaxCall($host);
    if (!$call) {
        die("Cannot contact host.\n");
    }
    $success = false;
    $time_start = microtime(true);
    // poke
    if ($response = $call->poke()) {
        // end timer before decode
        $time_end = microtime(true);
        $frame->load($response);
        if ($frame->messagetype == 'ping_response') {
            $success = true;
        }
    }
    if (@$success) {