Call routing based on extension subnet possible?

I run an Asterisk PBX at home, and want to do something that may or may not be possible. I’m not looking for someone to do this for me, I’d just appreciate being told if it’s possible, and perhaps given a pointer in the right direction.

I run a SIP client on my iPhone connecting to Asterisk via TCP (connected in background too). It works very well. What I’d like to do, is when a call comes in for me, I’d like to be able to look at the subnet that the iPhone (running the SIP client), and if it’s on the local subnet I want the call sent to on ring group, and if it’s NOT on the local subnet, I want it sent to another ring group. Basically, if it’s not on the local subnet, I want to try the SIP client for a few rings, then start ringing the cell phone via GSM. If I’m at home, I only want to ring the SIP client.

I already have the ring groups set up, and I’m doing this right now with time conditions, where it calls one ring group during my normal work hours, and the other when I should be at home. The problem is, my “working hours” are anything but normal, and a fixed schedule doesn’t work very well at all for me.

Any input/advice/thoughts? Is what I’m looking to do possible? I had also thought of writing a script to scan my DHCP leases file at home and manually make the change by calling asterisk at the command line… I didn’t look to far into the possibility of that because it’d be so much nicer if I could just do it as a rule in Asterisk.

Thanks for taking the time to read.

Seems there was a variable that may have what you desired but couldn’t find it. This does work however:


Both provide the IP addr of the registered . First option permits to be (unique) partial match, second requires exact match; you could call either from AGI script. Seems less than elegant but both work. You need to provide the additional logical for the dialplan

you can probably find the stuff that you need by analyzing the SIP_HEADER call variable. you may want to parse ${SIP_HEADER(From)} or ${SIP_HEADER(Contact)}.