The designation of whether a call is off-net vs. on-net is somewhat arbitrary, and in general depends on which gateway/trunk a call ingresses/egresses from. The CUCM admin can designate a particular 'route pattern' as off-net or on-net; route patterns in turn are associated with a particular gateway, trunk, or route-list (which in turn can can point to a group of gateways/trunks.)
So, a comprehensive approach is typically something like:
- Determin the CDR origination and/or destination device name of the call
- Get a list of all the gateway, trunk device names and see if the orig/dest is a gateway or trunk
- If so, determine which route pattern is associated to the gateway/trunk
- Determine whether the route pattern is designated as off-net or on-net
This will require reading/caching some data via AXL, i.e. device names and types, route pattern->device associations, route pattern properties, etc.
A simpler approach could just have the app user enter/identify the unique orig/dest device names as off-net vs. on-net.