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') { // wait for a call answer signal, then transfer while ($i->messagetype != 'answer') {
server char(12), source char(12), ended char(12), server char(12), time datetime, clear_code char(32) ); */ if (!file_exists('capture.hex')) { die; } $t = new TCPDUMP_UDP_Decode('capture.hex'); $i = new IAX_Decode(); $blocks = $t->getBlocks(); foreach ($blocks as $block) { $i->load($block['data']); switch ($i->messagetype) { case 'new': CallRegister::register($i, $block['header']['dst']['ip'], $block['header']['src']['ip']); break; case 'hangup': $call = CallRegister::retrieve($i->fields['scalli'], $block['header']['dst']['ip']); if ($call['user']) { print "INSERT INTO call_log SET \n" . " number='{$call['dst']}', \n" . " user='******'user']}', \n" . " server='{$call['server']}', \n" . " source='{$call['source']}', \n" . " ended='{$call['ended']}', \n" . " time='" . date('Y-m-d H:i:s', strtotime($block['header']['time'])) . "', \n" . " clear_code='{$i->data['hangup_cause']}';\n\n"; } CallRegister::unregister($i, $block['header']['dst']['ip'], $block['header']['src']['ip']); break; case 'accept': break; } }
// 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) { $time = number_format(($time_end - $time_start) * 1000, 1); print "Ping to {$host} took {$time}ms\n"; } else { print "Ping to {$host} received no response.\n"; } // destroy + end unset($call); if ($n != $packets) { usleep($delay * 1000); }
#!/usr/bin/env php <?php /** * @desc Basic stream decoder for Libpcap + IAX2 * Usage: tcpdump -U -s0 -w- port 4569 | ./info.php * * @author Leo Brown <*****@*****.**> * */ require '../../Classes/udp_decode.class.php'; require '../../Classes/iax_decode.class.php'; $t = new UDP_Decode('php://stdin'); $i = new IAX_Decode(); while ($packet = $t->getPacket()) { if (!@$packet['udp']) { continue; } $i->load($packet['udp']['packet']); if ($i->messagetype && $i->messagetype != 'voice') { print "{$packet['ip']['header']['src']}\t-> {$packet['ip']['header']['dst']}" . "\t {$i->messagetype}\n"; } }