Register active: Difference between revisions

From VoIPmonitor.org
Jump to navigation Jump to search
No edit summary
Line 14: Line 14:
  exec("echo 'listregisters' | nc 127.0.0.1 5029",$retstr,$rt);
  exec("echo 'listregisters' | nc 127.0.0.1 5029",$retstr,$rt);
  $data=json_decode($retstr[0]);
  $data=json_decode($retstr[0]);
  if (!array_key_exists ("1",$data)) exit; #ensure some active register(s) in list
  if (!array_key_exists ("2",$data)) exit; #ensure some active register(s) in list
   
   
  $regkeys=$data[0];
  $regkeys=$data[0];
Line 21: Line 21:
   
   
  foreach ($reglist as $n=>$item) {
  foreach ($reglist as $n=>$item) {
        var_dump($item[$sipcallerip_key]);
         if ($item[$sipcallerip_key] == $searchVal) var_dump($item);
         if ($item[$sipcallerip_key] == $searchVal) var_dump($item);
  }
  }
  ?>
  ?>

Revision as of 14:51, 20 July 2020

How to list all active registrations from single IP using the API

Usage

Following register_active.php script will print detail about all ACTIVE registrations done from single IP using ```managerip=127.0.0.1``` and ```managerport=5029```

example for use:

active_register.php "192.168.43.212"

Script

<?php
if (!array_key_exists ("1",$argv)) exit; #ensure argument passed
$searchVal=ip2long($argv[1]);

exec("echo 'listregisters' | nc 127.0.0.1 5029",$retstr,$rt);
$data=json_decode($retstr[0]);
if (!array_key_exists ("2",$data)) exit; #ensure some active register(s) in list

$regkeys=$data[0];
$sipcallerip_key=(array_search("sipcallerip",$regkeys));
$reglist=$data; array_shift($reglist); array_shift($reglist); #skip two items at begin

foreach ($reglist as $n=>$item) {
        if ($item[$sipcallerip_key] == $searchVal) var_dump($item);
}
?>