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

"SIP/2.0/WSS 192.0.2.99;rport=55887;**received=11.55.178.245**;branch=z9hG4bK6171652"

just need the bold part between "received=11.55.178.245" . 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:

https://wiki.asterisk.org/wiki/display/AST/Operators

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.