Check IP adddress

Hi all
I want use asterisk for connect 3 office, but i want this
First office have IP address 111.111.111.111 and there are many clients
Second office 222.222.222.222.222 there are many clients
Third office 111.111.222.222 the are only the IVR

It is a possible read the IP address the IVR form first office or second office, and if it is wrong hangup the call?
Eugenia

On Wednesday 12 February 2025 at 20:16:38, sipandcall via Asterisk Community
wrote:

I want use asterisk for connect 3 office, but i want this
First office have IP address 111.111.111.111 and there are many clients
Second office 222.222.222.222.222 there are many clients
Third office 111.111.222.222 the are only the IVR

It is a possible read the IP address the IVR form first office or second
office, and if it is wrong hangup the call?

Each office would be connected to Asterisk as an endpoint, pointing to a context
within the dialplan.

That context can then decide what to do with the call.

If that answer doesn’t satisfy your question, please give more details about
your actual Asterisk setup, showing how endpoint devices at “first office” and
“second office” are connecting in to Asterisk (wherever that is).

I really don’t understand how you have a “third office” containing only an IVR.

Also, is “hang up the call” the best way of dealing with mis-routed callers?

Antony.


“Microsoft’s profit margins require a monopoly lock on the market; thus,
they’re stuck with being predatory evil bastards. The moment they stop being
predatory evil bastards, their stock price will tank and their options pyramid
will crash and it will be all over.”

  • Eric S Raymond

Hi Pooh, thanks for your answer.
First office is to Milan, second office is to Berlin and the IVR is in the web farm.
When i call the the IVR from Milan or Berlin i dont want start the call if the nos is my IVR.
The IVR can answer other companies, but if the operator wrong the number and answer other IVR my company have the cost
The IVR have the IP and i want the filter, is my IVR so answer, not is my IVR close the call or not answer

I think they were saying they had multiple endpoints in the first two offices, not a satellite PBX in each. If it were satellite PBXes, one would match by address, everything would fall out in the wash.

Taking the question literally, you can use the pjsip remote_address option in the CHANNEL function, however, the first thing to consider would simply be to firewall your SIP port number, with second choice to be to use PJSIP ACL feature.

Please note that IVR is not a term used by Asterisk. You can use Asterisk to implement interactive voice response, but Asterisk only has lower level operations for doing this. If you actually want an answer for FreePBX, you are asking in the wrong place.

Hi david551 thnks for your solutions.
Hi read any web-page but i dont fine many solution for “remote_address”
I read i need add in extensions.conf and this is my

[IVR]
exten => _X.,1,NoOp()
exten => _X.,n,Set(remote_addr=${CHANNEL(pjsip,remote_addr)})
exten => _X.,n,Dial(PJSIP/${EXTEN}@IVR)

And this is log in console

WARNING[638][C-00000001]: func_channel.c:574 func_channel_read: Unknown or unavailable item requested: 'pjsip,remote_addr'

Now i want try with ACL

I try but dont work ACL
Other solution?

You need to actually show configuration, full console output, and SIP traffic.

This is the extension for IVR

[ivr]
exten => _80X.,1,NoOp()
exten => _80X.,n,Set(remote_addr=${CHANNEL(pjsip,remote_addr)})
exten => _80X.,n,Dial(PJSIP/${EXTEN}@IVR)

I want connect only to my IP, 111.111.222.222

And this is the pjsip to IVR

[IVR]
type = aor
contact = sip:111.111.222.222
maximum_expiration = 3600
default_expiration = 120

[IVR]
type = identify
endpoint = IVR
match = 111.111.222.222

[IVR]
type = endpoint
context = ivr
disallow = all
allow = ulaw
allow = alaw
allow = gsm
force_rport = yes
rewrite_contact = yes
direct_media = no
trust_id_inbound = yes
language = de
aors = IVR
transport = transport-udp

I see the ACL and add the acl.conf

[ivr]
permit=111.111.222.222 ;IVR
deny=0.0.0.0/0.0.0.0

Thanks
Eugenia

You never referenced the ACL on the endpoint[1]. That will prevent incoming traffic not from the given IP address from being acceptable for the endpoint. If this ISN’T what you want to happen you’ll need to specify more - as I’m slightly confused by “connect only to my IP” which I read as outgoing.

[1] res_pjsip - Asterisk Documentation

Also, I think permit and deny are in the wrong order.

There’s no full console output, so we can’t see why the CHANNEL function is failing.

What do you need?

Enable full log. Set verbosity to at least 3. There is no need to enable debugging at first, as it can be very noisy, but it might be needed later. Use “pjsip set logger on”. Provide the contents of /var/log/asterisk/full covering the whole call.

Hi David, this is the file

[2025-02-14 18:51:47] VERBOSE[488] asterisk.c: Remote UNIX connection
[2025-02-14 18:51:47] VERBOSE[2406] asterisk.c: Remote UNIX connection disconnected
[2025-02-14 18:51:47] VERBOSE[2407] dial.c: Called 805100100@ivr
[2025-02-14 18:51:47] VERBOSE[2408][C-00000005] pbx.c: Executing [805100100@ivr:1] NoOp("Local/805100100@ivr-00000004;2", "") in new stack
[2025-02-14 18:51:47] WARNING[2408][C-00000005] func_channel.c: Unknown or unavailable item requested: 'pjsip,remote_addr'
[2025-02-14 18:51:47] VERBOSE[2408][C-00000005] pbx.c: Executing [805100100@ivr:2] Set("Local/805100100@ivr-00000004;2", "ext_ip=") in new stack
[2025-02-14 18:51:47] VERBOSE[2408][C-00000005] pbx.c: Executing [805100100@ivr:3] Set("Local/805100100@ivr-00000004;2", "ext_ip=") in new stack
[2025-02-14 18:51:47] VERBOSE[2408][C-00000005] pbx.c: Executing [805100100@ivr:4] Dial("Local/805100100@ivr-00000004;2", "PJSIP/805100100@IP01") in new stack
[2025-02-14 18:51:47] VERBOSE[2408][C-00000005] app_dial.c: Called PJSIP/805100100@IP01
[2025-02-14 18:51:47] VERBOSE[2392] res_pjsip_logger.c: <--- Transmitting SIP request (994 bytes) to UDP:77.239.128.7:5060 --->
INVITE sip:2024%23805100100@77.239.128.7 SIP/2.0
Via: SIP/2.0/UDP 15.235.192.70:5060;rport;branch=z9hG4bKPj076da4fc-c6ea-41c9-a73f-3a5999403edd
From: "Anonymous" <sip:anonymous@anonymous.invalid>;tag=40493f8b-43a5-4aca-af9c-b73d8bfeb51c
To: <sip:23805100100@77.239.128.7>
Contact: <sip:asterisk@15.235.192.70:5060>
Call-ID: d0408c87-4c35-474b-abb4-ff4a5a41f4a9
CSeq: 22794 INVITE
Allow: OPTIONS, REGISTER, SUBSCRIBE, NOTIFY, PUBLISH, INVITE, ACK, BYE, CANCEL, UPDATE, PRACK, MESSAGE, INFO, REFER
Supported: 100rel, timer, replaces, norefersub, histinfo
Session-Expires: 1800
Min-SE: 90
Max-Forwards: 70
User-Agent: gsm-gw-3.4.1
Content-Type: application/sdp
Content-Length:   284

v=0
o=- 427406463 427406463 IN IP4 15.235.192.70
s=Asterisk
c=IN IP4 15.235.192.70
t=0 0
m=audio 12490 RTP/AVP 0 8 3 101
a=rtpmap:0 PCMU/8000
a=rtpmap:8 PCMA/8000
a=rtpmap:3 GSM/8000
a=rtpmap:101 telephone-event/8000
a=fmtp:101 0-16
a=ptime:20
a=maxptime:140
a=sendrecv

[2025-02-14 18:51:47] VERBOSE[510] res_pjsip_logger.c: <--- Received SIP response (344 bytes) from UDP:77.239.128.7:5060 --->
SIP/2.0 100 Trying
From: Anonymous <sip:anonymous@anonymous.invalid>;tag=40493f8b-43a5-4aca-af9c-b73d8bfeb51c
To: <sip:805100100@77.239.128.7>
Call-ID: d0408c87-4c35-474b-abb4-ff4a5a41f4a9
CSeq: 22794 INVITE
Via: SIP/2.0/UDP 15.235.192.70:5060;rport=5060;branch=z9hG4bKPj076da4fc-c6ea-41c9-a73f-3a5999403edd
Content-Length: 0


[2025-02-14 18:51:48] VERBOSE[510] res_pjsip_logger.c: <--- Received SIP response (733 bytes) from UDP:77.239.128.7:5060 --->
SIP/2.0 200 OK
From: Anonymous <sip:anonymous@anonymous.invalid>;tag=40493f8b-43a5-4aca-af9c-b73d8bfeb51c
To: <sip:805100100@77.239.128.7>;tag=wq5B4HmfwBa
Call-ID: d0408c87-4c35-474b-abb4-ff4a5a41f4a9
CSeq: 22794 INVITE
Require: timer
Via: SIP/2.0/UDP 15.235.192.70:5060;rport=5060;branch=z9hG4bKPj076da4fc-c6ea-41c9-a73f-3a5999403edd
Contact: <sip:805100100@77.239.128.7:5060>
Session-Expires: 1800;refresher=uas
Allow: ACK,INVITE,BYE,CANCEL,OPTIONS,INFO
Content-Type: application/sdp
Content-Length: 200

v=0
o=- 2321554821 4195353040 IN IP4 77.239.128.7
s=-
c=IN IP4 77.239.128.112
t=0 0
m=audio 28390 RTP/AVP 0 8 101
a=rtpmap:101 telephone-event/8000
a=fmtp:101 0-15
a=ptime:20
a=maxptime:150

[2025-02-14 18:51:48] VERBOSE[2392] res_rtp_asterisk.c: 0x7fd6b8007570 -- Strict RTP learning after remote address set to: 77.239.128.112:28390
[2025-02-14 18:51:48] VERBOSE[2392] res_pjsip_logger.c: <--- Transmitting SIP request (430 bytes) to UDP:77.239.128.7:5060 --->
ACK sip:805100100@77.239.128.7:5060 SIP/2.0
Via: SIP/2.0/UDP 15.235.192.70:5060;rport;branch=z9hG4bKPjc4bbcadb-00b9-4806-99ae-916f0d685854
From: "Anonymous" <sip:anonymous@anonymous.invalid>;tag=40493f8b-43a5-4aca-af9c-b73d8bfeb51c
To: <sip:2024%23805100100@77.239.128.7>;tag=wq5B4HmfwBa
Call-ID: d0408c87-4c35-474b-abb4-ff4a5a41f4a9
CSeq: 22794 ACK
Max-Forwards: 70
User-Agent: gsm-gw-3.4.1
Content-Length:  0


[2025-02-14 18:51:48] VERBOSE[2408][C-00000005] app_dial.c: PJSIP/IP01-00000004 answered Local/805100100@ivr-00000004;2
[2025-02-14 18:51:48] VERBOSE[2407] dial.c: Local/805100100@ivr-00000004;1 answered
[2025-02-14 18:51:48] VERBOSE[2407] pbx.c: Launching Playback(demo-congrats) on Local/805100100@ivr-00000004;1
[2025-02-14 18:51:48] VERBOSE[2410][C-00000005] bridge_channel.c: Channel PJSIP/IP01-00000004 joined 'simple_bridge' basic-bridge <37126a76-bdba-46b7-91fb-ad997b9389aa>
[2025-02-14 18:51:48] VERBOSE[2407] file.c: <Local/805100100@ivr-00000004;1> Playing 'demo-congrats.gsm' (language 'en')
[2025-02-14 18:51:48] VERBOSE[2408][C-00000005] bridge_channel.c: Channel Local/805100100@ivr-00000004;2 joined 'simple_bridge' basic-bridge <37126a76-bdba-46b7-91fb-ad997b9389aa>
[2025-02-14 18:51:48] VERBOSE[2410][C-00000005] res_rtp_asterisk.c: 0x7fd6b8007570 -- Strict RTP switching to RTP target address 77.239.128.112:28390 as source
[2025-02-14 18:51:53] VERBOSE[2410][C-00000005] res_rtp_asterisk.c: 0x7fd6b8007570 -- Strict RTP learning complete - Locking on source address 77.239.128.112:28390
[2025-02-14 18:52:18] VERBOSE[2408][C-00000005] bridge_channel.c: Channel Local/805100100@ivr-00000004;2 left 'simple_bridge' basic-bridge <37126a76-bdba-46b7-91fb-ad997b9389aa>
[2025-02-14 18:52:18] VERBOSE[2408][C-00000005] pbx.c: Spawn extension (ivr, 805100100, 4) exited non-zero on 'Local/805100100@ivr-00000004;2'
[2025-02-14 18:52:18] VERBOSE[2410][C-00000005] bridge_channel.c: Channel PJSIP/IP01-00000004 left 'simple_bridge' basic-bridge <37126a76-bdba-46b7-91fb-ad997b9389aa>
[2025-02-14 18:52:18] VERBOSE[2392] res_pjsip_logger.c: <--- Transmitting SIP request (454 bytes) to UDP:77.239.128.7:5060 --->
BYE sip:805100100@77.239.128.7:5060 SIP/2.0
Via: SIP/2.0/UDP 15.235.192.70:5060;rport;branch=z9hG4bKPj705c3ef5-fa2d-4853-a87e-9312d01a59e7
From: "Anonymous" <sip:anonymous@anonymous.invalid>;tag=40493f8b-43a5-4aca-af9c-b73d8bfeb51c
To: <sip:2024%23805100100@77.239.128.7>;tag=wq5B4HmfwBa
Call-ID: d0408c87-4c35-474b-abb4-ff4a5a41f4a9
CSeq: 22795 BYE
Reason: Q.850;cause=16
Max-Forwards: 70
User-Agent: gsm-gw-3.4.1
Content-Length:  0


[2025-02-14 18:52:18] VERBOSE[510] res_pjsip_logger.c: <--- Received SIP response (396 bytes) from UDP:77.239.128.7:5060 --->
SIP/2.0 200 OK
From: Anonymous <sip:anonymous@anonymous.invalid>;tag=40493f8b-43a5-4aca-af9c-b73d8bfeb51c
To: <sip:805100100@77.239.128.7>;tag=wq5B4HmfwBa
Call-ID: d0408c87-4c35-474b-abb4-ff4a5a41f4a9
CSeq: 22795 BYE
Via: SIP/2.0/UDP 15.235.192.70:5060;rport=5060;branch=z9hG4bKPj705c3ef5-fa2d-4853-a87e-9312d01a59e7
Allow: ACK,INVITE,BYE,CANCEL,OPTIONS,INFO
Content-Length: 0

For start the call i use this command

sudo asterisk -rx "channel originate Local/805100100@ivr application Playback demo-congrats"

And i add this row on pjsip.conf

[ivr]
type=acl
acl=ivr

Thanks David

Maybe 3 wasn’t enough, as you aren’t getting the dialplan logged, however there is a reference to a local channel, and the CHANNEL function needs to be run on the original, PJSIP, channel.

i must repeat?

You should know if you are using a local channel. If you are, that is why CHANNEL didn’t work. If you don’t think you are, I would need the verbosity increasing to understand where the local channel is coming from.

This is th machine for test, but is the copy for the machine in production.
I use the command originate, for start the call.
Recap
I want when start the call i read the IVR IP address and if not is my IP i need close the call

Please provide your originate application call, AMI action, or CLI command.

For example if the call start from SIP_200 to 805100100?