[SOLVED] Get the called number


We have an Asterisk 11 on an Ubuntu 14.04.
Our SIP provider is ippi.fr, we have two external phone numbers with it.

We use our Asterisk to send and receive fax with FFA.
It works fine.

However, as we have two external numbers, we receive calls for them on the asterisk.

But we don’t know how to know which number was called and we need that.

Someone know if there is a variable to know the called number ? Not the CALLERID but one of our two external numbers.

Thanks !

${EXTEN}, but only if they are passing the number properly.


Thanks for your help but it’s not what i’m looking for or i’m not using it correctly.

The ${EXTEN} return the extension of the line of dialplan. (in my case “s”) see :

If i wasn’t clear, we have two external numbers :

We want to know which number is called.

EDIT: Maybe can i replace “s” extension by one of my external phone number ?

If your ITSP passed the number in the standard SIP way (request URI user part), I would expect an error message about the number not being found, so I assume your ITSP is not passing the called number, or not passing it in the standard SIP way. You will need to find out how they are passing it. It may be in the To: header. Unfortunately, whilst Asterisk will set To: based on CALLERID(dnid), in the versions I have looked at, it will not do the reverse. If that is the case, you will need to get the header and analyse it with string manipulation functions.

I’m assuming that you are quoting the dialplan directly under the context specified in sip.conf, not in some macro or subroutine.

For a well behaving ITSP, you would match using an extension pattern match, rather than explicitly reading ${EXTEN}.

Thanks, it’s a good idea. I didn’t think to check the header.

With :

I saw the called number on the line "To: "

Now, i just need to find a way to export this information.

Thanks for your help, i think i can handle it now. :smile:

Done with these lines

exten => s,n,Set(HEADER_TO=${SIP_HEADER(To)}) exten => s,n,Set(CALLED_NUMBER=${HEADER_TO:5:10})