How to extarct IP from VIA header

Hello all,

I’ve been trying to extract the “received=IP” part from the VIA header which we can access over PJSIP_HEADER(read,via), returns something like


just need the bold part between "received=" . I tried with specifying the char start length and end like Set(via=${PJSIP_HEADER(read,Via):45:20}), but since the IP length can change it doesn’t really help. Can someone please give me a hint?

The easiest way is probably with the : operator:

However you could probably also do it using SHIFT, with ; as the delimiter - don’t forget to quote it.

Has that substitution actually been made in the version returned by PJSIP_HEADER? Are you sure there isn’t a specific function to return that value?

Specifically, I would have thought ${CHANNEL(pjsip,remote_addr)} would have given you this information.

Hi david551, thanks much for this. I was able to get the desired out put by simply adding the func you provided and after using ${CUT} to remove the rport

exten => 1,1,Set(remote_addr=${CHANNEL(pjsip,remote_addr)})
same => n,Set(IP=${CUT(remote_addr,:,-1)})

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