Find out where a sip user is

Ok so lets say I have a user who has a username and password to use my asterisk server.

For this example Lets say the IP address says the person is in Melbourne Australia.

They dial 9419XXXX
But in our dial plan we have melbourne as 03.

So what I really need is away to find out where the original call is coming from.

I understand that we can call System() to run a system command like say{USERSIPADDRESS}

Which would give me the users information of what state his IP address was currently in.

But question 1) how do a get System to return a response that Asterisk can read and then use a gotoif function that lets me choice where it goes from there.

If anyone can help that would be great


Initial disclaimer - I may not have understood your requirement completely :smiley:

First suggestion seems to be try to re-arrange your dial plan to accommodate calls dialed in both local, country & international formats.

If you still need to make that http request to get callers location, use an AGI call from your dial plan.

I usually write my AGI in php and use phpagi - lots of examples on the web, etc.

You can use the asterisk function CHANNEL(peerip) to get the ip of the user, then use php cUrl to make your http call. Finally (from within the AGI script) set an asterisk channel variable with the result of your http request (e.g. PEERLOC). Then in your dialplan you can access {PEERLOC} in the condition of your GotoIf.


Another proposal from my understanding of the requirement :unamused:

If You have different users located in different areas which shoud be able to use Your asterisk in a “local based dial manner” meaning each of the users dialing in their repeective local format then one solution would be to associate the relevant informations (area code, country code andd maybe long distance and international prefix) to the peer-Definition (as variables either in sip.conf or in realtime) and afterwards “reformat” the dialed number under respect of these variables to an internal format which is than routable inside Your asterisk.

If my interpretaion of Your requirement is correct and Your clients/peers don’t use variable locations (where IP-detection may be the only solution) feel free to contact me for furtheer assistance.

Thanks I will give this a go.
Its interesting Asterisk I mean, I for 16 years have done PHP and DB (MySQL, MongoDB) but got borded of it lately, Asterisk as respraked my interest in all of this. Trying to work out the best way to do things whether be contact a PHP or run a System command.