Distribute my DIDs throughout the day

Hello there,

I have a pool of 200 DIDs issued to us by the SIP provider. And i want to use these 200 DIDs throughout the day, probably something like 10 DIDs for 2 hours. And then repeat the cycle. The DIDs will be the callerID as sent to the SIP provider side.

Can i do this via the dialplan (extensions.conf) of my asterisk server based on the system time? I am running asterisk 16.30.1

Any guidance?

Do you need to change the numbers for outgoing or incoming calls?

I think he means caller ID, rather than direct INCOMING dialling numbers, so outgoing. Unfortunately DID has become redefined as a rented PSTN number, in the VoIP customer base.

I’m not sure if he means an account number, as I can’t think why one would want to load balance directory numbers.

Provided that these are eiher the From: user or the From: user does not change, it is a simple matter of programming. The simplest way is probably to use random numbers to pick the caller ID for the call, just take the random number modulo the the number of caller IDs, although you could make it a function of the time of day, or even EPOCH divided by the length of each slot, and then taken modulo the number of caller IDs.

Gaps in the numbers will make things a bit more difficult although you can use extensions in a special context as a lookup mechanism.

Yes, i am referring to the callerID on the outgoing calls. The reason i want to distribute calls across these 200 callerIDs is that i want the entire 200 to be utilized evenly throughout the day.

Is there any better approach other than what i asked/requested for above?

If all the numbers are in a range then you can write a series of GotoIfTime commands to select the number to use. Another option is to use a randomizer and use different numbers throughout the day. Say you have 10 phone numbers:

Then I would define them in a global list like this:


In my DialPlan I would have something like:

Exten => _X.,1,Set(CALLERID(num)=${C${RAND(10,19)}})

This would have Asterisk set the callerID to one of these numbers. You could use the same concept as above and create groups of numbers such as ones starting with A for the first hour, B for the second hour etc. I have always found it a lot more effective and easier to do this kind of work in an AGI rather then in the dialplan its self.

if your numberes are in a range just pick one random
if not add them to astDB and select a random from there

EXTEN => _X!,1,Set(CALLERID(num)=180012345${RAND(0,1)]${RAND(0,9)}${RAND(0,9)})

OutgoingPool/0=first number
OutgoingPool/1=second number
OutgoingPool/199=last number

EXTEN => _X!,1,Set(CALLERID(num)=${DB(OutgoingPool/${RAND(0,199)}})

Question what is the use case for this it sound like you are trying to preform SPIT calls

1 Like

Why do you need this feature? If you do not have 200 callers, every caller will eventually deliver several numbers to callees. If it’s a random process, then there is no relation between CallerID and caller. This will most likely mislead callers. The only application that comes to mind are the popular robocalls.

That said, it may not be enough to fiddle with the From header. People using something like Homer 7 can track things after weeks and they would be able to figure out what is going on by evaluating all headers. You might end up being blocked in the future regardless of what CallerID you are using.

That’s what you want to do, not why you need to do it.

So, isn’t there a way to avoid getting blocked?

Not for you. The crux of the matter is that there are many more SIP headers than the From header that can be used to say at least something about the caller.

In case someone starts to massively abuse the From field, I am pretty sure that someone here would describe this and give detailed info on how to block this on various levels. If the number blocks were not purchased but, let’s say, fell off the truck, then this all amounts probably to a crime.

You still haven’t described what your intentions are for doing this. Maybe there is a sensible reason. Otherwise, you can assume that the vast majority of people here want to learn something about one of the more difficult areas of computer science and have fun doing it, regardless of whether they are professionals or amateurs like me. That rules out recipes for nonsense.

Hi, I take it that this is for a callcenter and that Truecaller and Hiya and all the other stupid apps on the phones are blocking your numbers. so what i do on our system is as follows.

Create a list in Excel that randomizes and sets your numbers, lets say for the day there is 200 numbers so they should look something like this.

exten => 2005,1,Set(DB(may2023/202306161)=xxxxxxxxx0)
exten => 2005,2,Set(DB(may2023/202306162)=xxxxxxxxx0)
exten => 2005,3,Set(DB(may2023/202306163)=xxxxxxxxx0)
exten => 2005,4,Set(DB(may2023/202306164)=xxxxxxxxx0)
exten => 2005,5,Set(DB(may2023/202306165)=xxxxxxxxx0)
exten => 2005,6,Set(DB(may2023/202306166)=xxxxxxxxx0)
exten => 2005,7,Set(DB(may2023/202306167)=xxxxxxxxx0)
exten => 2005,8,Set(DB(may2023/202306168)=xxxxxxxxx0)
exten => 2005,9,Set(DB(may2023/202306169)=xxxxxxxxx0)
exten => 2005,10,Set(DB(may2023/2023061610)=xxxxxxxxx0)
exten => 2005,11,Set(DB(may2023/2023061611)=xxxxxxxxx0)

now this you load into the Asterisk Database with something like this:
console dial 2005@extensions

that loads the numbers with the dates into the database. I did not do it in a while so dont quote me on the exact console dial method.

once it is loaded then you use it in extensions.conf via something like this.


exten => s,1,GotoIfTime(00:01-11:30,,,?first)
exten => s,2,GotoIfTime(11:30-15:30,
exten => s,3,GotoIfTime(15:30-23:59,,,*?third)

exten => s,n(first),Set(DATEONE=${STRFTIME(${EPOCH},Africa/Cairo,%Y%m%d)}1)
exten => s,n,GoTo(getnum)
exten => s,n(second),Set(DATEONE=${STRFTIME(${EPOCH},Africa/Cairo,%Y%m%d)}2)
exten => s,n,GoTo(getnum)
exten => s,n(third),Set(DATEONE=${STRFTIME(${EPOCH},Africa/Cairo,%Y%m%d)}3)
exten => s,n,GoTo(getnum)
exten => s,n(getnum),Set(CELNUMONE=${DB(may2023/${DATEONE})})
exten => s,n,Set(CALLERID(number)=${CELNUMONE})
exten => s,n,Set(CALLERID(name)=${CELNUMONE})

and that is it. you just have to use this concept and modify to your liking, however i know for a fact that there is an easier way in doing this and tpeople will most probably help. something like adding all numbers to a file and then read it from a file or something or doing a round robin with all the numbers or something.

Hope the above helps.

Not judging; here’s another way:




7 */2 * * *    asterisk    shuf -n 10 /etc/asterisk/mydids.txt > /etc/asterisk/activedids.txt


same => n,Set(CALLERID(num)=${FILE(/etc/asterisk/activedids.txt,${RAND(1,10)},1,l)})

You are always alowed to judge, im fairly new to Asterisk and thats why i said there is always a better way of doing something. i have seen it over and over. and thats why i love this Asterisk Community, Some on here are exceptionally helpfull without any issues but then you get those odd ones out that will instead of help, rather critisize and complain when you need help. Especially when you using an older asterisk and not the most recent updated ones or like when you use sip instead of pjsip and all those stuff. instead of giving advise they would rather just flame you and so on. But thanks to those who do actually go out of their way in trying to help. There is always reasons why a person uses a certain version of asterisk. Might it be Apps, Might it be Codecs, Might it be pjsip that is just terrible to use. what ever the case may be.

So thanks to the community that are here to help with no questions asked.

Thank you for trying to help as well. It is very satisfying to see newer users like yourself move from asking questions to posting answers in such a short time frame.

There is not (yet) as much documentation for chan_pjsip as chan_sip, but most specific chan_pjsip issues seem to be addressed in a fairly timely manner on the forums.

Hi, Yes thanks i know pjsip people do try and help when there is issues, but when i tried it on our systems which is sip only and all our software is sip only the pjsip just gave me a bunch of headaches. either not connecting or connecting with single side audio, or connecting but loosing registration all that weird kind of issues where sip never gave that issues. so yes we did upgrade most stuff from asterisk 1.16.1 to 1.18 which is the last cracked version of G723 and G729 and i could not find any of those codecs for any higher asterisk. and not even sure if i can disable pjsip and enable sip. and even worse than that the 1 system we have has some weird app running on asterisk that we cannot get to install on any other asterisk and we need it for our software. so kind of a stone wall mountain.

And with what i learned up to now, i will always try and help fellow Asterisk Community members as that is what we should be doing. The asterisk Community is small and we need to stick together.

So Thank You penquinpbx for your kind words above, We really appreciate it.

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