Getting registered peers via query or api

I am using asterisk real time with mysql and need to retrieve the status of users/peers via a query. Basically fetch the equivalent of ‘CLI>sip show peers’ and filter the list with the peers which have a registered ip address. How can I get this info programmatically - ideally via a query. Otherwise via an api without having to use CLI.

Thank you for your help!

You want to check that which user is registered right??? There are many ways to achieve this.

  1. run the console command Shell_exec(asterisk -rx “sip show peer peername”’), grep the ip, if it is not 0.0.0.0 , it means it is registered.

  2. you can check the sip users table for latest ip address. The below link will tell you how to read from the database from asterisk dialplan.

itdiscussiongroup.com/?p=35