Dial(PJSIP/xx) – Finding The IP Address It Connected To

Home » Asterisk Users » Dial(PJSIP/xx) – Finding The IP Address It Connected To
Asterisk Users 9 Comments

Hi,

When dialling a remote SIP host with PJSIP, is it possible either within the dialplan or via the AMI to find out the IP address of the remote host?

If for example a remote host has multiple A records, I would like to know which one Asterisk has connected to.

We have an issue with some remote hosts that send INVITE messages back periodically mid-call, but because of our firewall the messages aren’t being received by Asterisk, therefore not being answered, and the remote host is dropping the call.

We can’t open those hosts up by default in the firewall because customers could choose any SIP destination, but if I could allow the specific remote address for the duration of the call, it would solve some issues. I could use AGI scripts to add/remove firewall rules as needed.

Unless, that is, there’s a better way?

I’m using Asterisk 18.7.1 FWIW.

Cheers, Kingsley.

9 thoughts on - Dial(PJSIP/xx) – Finding The IP Address It Connected To

  • Thanks, that looks perfect. What is the syntax? I have tried a few things but none work:

    exten => s,n,Set(tmp=CHANNEL(PJSIP,remote_addr))exten =>
    s,n,Set(tmp=CHANNEL(PJSIP/remote_addr))exten =>
    s,n,Set(tmp=${CHANNEL(PJSIP,remote_addr)})exten =>
    s,n,Set(tmp=${CHANNEL(PJSIP/remote_addr)})exten =>
    s,n,Set(tmp=CHANNEL(pjsip,remote_addr))exten =>
    s,n,Set(tmp=CHANNEL(pjsip/remote_addr))exten =>
    s,n,Set(tmp=${CHANNEL(pjsip,remote_addr)})exten =>
    s,n,Set(tmp=${CHANNEL(pjsip/remote_addr)})exten =>
    s,n,Set(tmp=CHANNEL(remote_addr))exten =>
    s,n,Set(tmp=CHANNEL(remote_addr))exten =>
    s,n,Set(tmp=${CHANNELremote_addr)})exten =>
    s,n,Set(tmp=${CHANNEL(remote_addr)})

    — Executing [s@register-answer:5] Set(“PJSIP/btipx-00000005”,
    “tmp=CHANNEL(PJSIP,remote_addr)”) in new stack — Executing [
    s@register-answer:6] Set(“PJSIP/btipx-00000005”,
    “tmp=CHANNEL(PJSIP/remote_addr)”) in new stack[Nov 4 11:41:20]
    WARNING[11722][C-00000003]: func_channel.c:463 func_channel_read:
    Unknown or unavailable item requested: ‘PJSIP,remote_addr’

  • Hmm, I can’t get this to work. This dialplan code:

    exten => s,n,NoOp(### state=${CHANNEL(state)} ##)
    exten => s,n,NoOp(### remote_addr=${CHANNEL(pjsip,remote_addr)} ##)

    logged this:

    — Executing [s@register-answer:5] NoOp(“PJSIP/btipx-0000000b”, “### state=Up ##”) in new stack
    [Nov 4 12:31:00] WARNING[974]: pjsip/dialplan_functions.c:834 channel_read_pjsip: No transport information for channel PJSIP/btipx-0000000b
    [Nov 4 12:31:00] WARNING[12206][C-00000006]: func_channel.c:463 func_channel_read: Unknown or unavailable item requested: ‘pjsip,remote_addr’
    — Executing [s@register-answer:6] NoOp(“PJSIP/btipx-0000000b”, “### remote_addr= ##”) in new stack

    That sub was called from this context:

    Dial(“Local/2.1.01162687107-btipx@dial_pstn_carrier-00000011;2”, “PJSIP/btipx/sip:01162687107@88.151.41.45:5060,,r(ring)b(dial_pstn_carrier^set_handler^1(btipx,2,1,1))U(register-answer^2^1)”)

    Am I doing something silly?

    Cheers, Kingskey,

  • Right OK, a bit of a mystery then.

    I have tried to figure out whether this information is available via the AMI but I haven’t been able to find anything.

    Do you know whether it is possible to get the remote_addr from the AMI?


    Cheers, Kingsley.

  • Hi,

    I’ve managed to establish that there are no events that convey this information, getting a list of channels doesn’t include that in the data and I didn’t manage to find any of the PJSIP AMI commands that returned it, so I think it isn’t possible.

    The only way I can think is to externally have tcpdump running capturing all SIP traffic and watch this and match up with the Call-Id. It seems messy but I can’t think of any other way (aside from doing an ngrep for local originated INVITEs but that amounts to much the same thing).


    Cheers, Kingsley.