Total number of extensions?


How can I know the total number of extensions in a Asterisk system? Is there any command?


What is an extension?

TL;DR First define exactly what counts as one extension.

That is difficult to calculate, given that the priority 1 in extensions.conf may be a wild card but subsequent priorities may be specific or overlapping wild card matches. I suspect you would also need to provide different mechanisms for Asterisk Realtime Architecture ones given that some of the lookups are done in real time, so Asterisk never sees the complete picture.

If you actually meant extensions in the FreePBX sense, and using its narrowest definition, even that is difficult, because SIP itself has no trunks or extensions, so you would need to examine the dialplan to determine how they are used. Also an analogue station line can really be a tie line, and therefore a trunk.

I doubt if the problem is covered by the Turing halting problem, but it could get close.

PS. For both chan_sip and chan_pjsip, it is possible to address a local VoIP phone directly from the dialplan, without there being a one to one correspondence between the phone and any entry in sip.conf or pjsip.conf (there need be no entry at all in the former). As the string used to do that can be generated dynamically, I think the Turning halting problem does apply here, so it become theoretically and not just practically impossible.

Firstly please tell us which version of Asterisk you are using.

Secondly please define “extension” - do you mean telephones, do you mean
numbers which can be dialled “internally” and may end up on a telephone, or a
ring group, or a queue, etc, do you mean something else?

Finally, and assuming you mean at least something to do with telephones, what
technology are you using to connect them - SIP (chan_sip or pjsip?), IAX,
DADHI, other?

Your question is way more ambiguous than you probably realise.


I mean a SIP telephones.

So, do you mean “the number of SIP telephones which are currently registered
on this server” or do you mean “the number of SIP endpoints which are defined
on this server, and which a telephone might register to”?

And, are you using chan_sip or chan_pjsip?


Pooh, I mean the number of SIP endpoints which are defined on my server, and which a telephone might register to under chan_pjsip.


Note that the number of telephones that are currently registered can exceed the number of endpoints, and that telephones never need to register to make calls and, although unusual for telephones, there is no fundamental requirement to register to receive calls, only that they address is known by some means.

One telephone may be associated with more than one endpoint.

There is no simple way of distinguishing a telelphone from a PBX (in fact many providers are probably in this situation, as they may offer a service intended for telephones, and actually have Asterisk systems use them).

Although such configurations are likely to be extremely rare, my observation that one chan_pjsip endpoint can be used to access arbitrary numbers of IP addresses and therefore telephones, and you don’t even need a chan_sip peer entry to do that, still applies.

Basically there can only be a simple answer if you apply enough simplifying assumptions, and because of that, there is no built in mechanism to perform such a count. Asterisk does not use the term extension, in the sense you are using it, and does not use the term trunk.

I don’t see an easy way of distinguishing between a telephone and an PBX registering, but otherwise do you mean endpoints for which there is at least one aor with max_contacts set? Do you want to go further and say that, in addition, no aor may have contact set?

Do you want to support this over ARA, or just for .conf files?

What is the underlying goal behind this question?

A PJSIP endpoint can have multiple contacts.

View all endpoints (online and offline)

pjsip show endpoints

View all contacts (active or nan)

pjsip show contacts

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.