**
EDIT The previous version of didn’t work the way I had hoped. I have changed it. I have edit this post with the new version.
**
This is what I have worked out…is it too much? Would love additional feedback…thanks again…I feel like im starting to wrap my head around some of this!
[macro-dialout-trunk-predial-hook]
exten => s,1,NoOp()
exten => s,n,GotoIf($[$["${CALLERID(dnid)}" = "911"] | $["${EMERGENCYROUTE}" = "YES"]]?s_CHANNLE_TYPE,1:s_exit,1)
exten => s_CHANNLE_TYPE,1,NoOp()
exten => s_CHANNLE_TYPE,n,GotoIF($["${CHANNEL(channeltype)}" = "PJSIP"]?s_PJSIP_IP,1)
exten => s_CHANNLE_TYPE,n,GotoIF($["${CHANNEL(channeltype)}" = "SIP"]?s_SIP_IP,1)
exten => s_CHANNLE_TYPE,n,Log(NOTICE, <Emergency CID OVERRIDE> Unable to get channel type. CID-IP Mapping not used.)
exten => s_CHANNLE_TYPE,n,Goto(s_exit,1)
exten => s_PJSIP_IP,1,NoOp()
exten => s_PJSIP_IP,n,Set(endpoint_addr=${CHANNEL(pjsip,remote_addr)})
exten => s_PJSIP_IP,n,Set(ip_addr=${CUT(endpoint_addr,:,1)})
exten => s_PJSIP_IP,n,GotoIF($ ["${ip_addr}" != ""]?s_CID_IP_MAP,1)
exten => s_PJSIP_IP,n,Log(NOTICE, <Emergency CID OVERRIDE> Unable to get endpoint ip from PJSIP channel. CID-IP Mapping not used.)
exten => s_PJSIP_IP,n,Goto(s_exit,1)
exten => s_SIP_IP,1,NoOp()
exten => s_SIP_IP,n,Set(ip_addr=${CHANNEL(sip,peerip)})
exten => s_SIP_IP,n,GotoIF($ ["${ip_addr}" != ""]?s_CID_IP_MAP,1)
exten => s_SIP_IP,n,Log(NOTICE, <Emergency CID OVERRIDE> Unable to get endpoint ip from SIP channel. CID-IP Mapping not used.)
exten => s_SIP_IP,n,Goto(s_exit,1)
exten => s_CID_IP_MAP,1,NoOp()
exten => s_CID_IP_MAP,n,GoSubIF(${REGEX("(192\.168\.7\.[0-9])" ${ip_addr})}?s_SetCID,1(5551117777)) ;location1
exten => s_CID_IP_MAP,n,GoSubIF(${REGEX("(192\.168\.8\.[0-9])" ${ip_addr})}?s_SetCID,1(5551118888)) ;location2
exten => s_CID_IP_MAP,n,GoSubIF(${REGEX("(192\.168\.9\.[0-9])" ${ip_addr})}?s_SetCID,1(5551119999)) ;location3
exten => s_CID_IP_MAP,n,GoSubIF(${REGEX("(192\.168\.0\.[0-9])" ${ip_addr})}?s_SetCID,1(5551110000)) ;location4
exten => s_CID_IP_MAP,n,Log(NOTICE, <Emergency CID OVERRIDE> Unable to find CID mapping for ${ip_addr} . CID-IP Mapping not used.)
exten => s_CID_IP_MAP,n,Goto(s_exit,1)
exten => s_SetCID,1,NoOp()
exten => s_SetCID,n,Set(CALLERID(num)=${ARG1})
exten => s_SetCID,n,Goto(s_exit,1)
exten => s_exit,1,NoOP()
exten => s_exit,n,MacroExit()