How to set up a node to say its IP address after boot up or in response to a DTMF command?

Surprised there is not already a post on how to do this… a search did not seem to show anything.

Nodes are often used on various networks and in portable situations (eg. hotels, office buildings, cafes, etc) where you may need to know the IP address of the node so that you can then connect to it by ssh, http, etc. If you don’t happen to have a monitor and keyboard/mouse with you to plug into the node there is no easy way to find out its IP address.

How can an ASL node be set up to announce its IP address after boot or in response to a DTMF command?

After reviewing other examples, here is what I did to solve that problem.

Danny/KB4MDD

1 Like

There are always more than one way to do anything in asterisk.

The method I use is basically creating a extension in extensions.conf within the same context as your phonepatch (autopathup) is in that looks like this

[my-pbxip]
exten=00,1,Set(MYADDR=${CURL(https://api.ipify.org?format=json)})
exten=00,2,Wait,3
exten=00,3,SayAlpha(${MYADDR})
exten=00,n,Hangup

You could create a new phone patch command and specify a NEW context that is the stanza name in this case [my-pbxip]

69=autopatchup,context=my-pbxip,noct=1,farenddisconnect=1,dialtime=9000,quiet=1

So, using it in this way, you would dial *6900 to fetch and playback the ext ip of your server

So, that’s a skinny way to do this effectively with 6 lines of text.

I actually use one entry in extensions.conf and use a gosub/goto to that from many contexts I use in the system. Including my sip-phones. This keeps me from re-writting in many places if something changes.

On occasion, the web address you use to extract the info will change or go down permanently, but some other ones are out there. They just need to output in a single text line from a single curl hit.
The one pointed to in my example I have been using for about 4 years now I think. Never a issue but It’s not all that often I use it. Probably more in script use than anything else.

Since I really do not know if a current install of ASL-Asterisk contains ‘curl’ you may need to install it

sudo apt-get install curl

It’s small and useful for a lot of things in the system

Edit:
So I forgot the startup option…
So, you have a option for a start-up macro in rpt.conf
You can issue the dtmf string in that startup macro.
See the wiki.
https://wiki.allstarlink.org/wiki/Rpt.conf#startup_macro.3D

/usr/local/etc/allstar.env:export SAY_IP_AT_BOOT=“enabled”

I added that line to /usr/local/etc/allstar.env and nothing happens after a reboot. I did also change the “smart” quotes to regular double quotes ("" vs “”) (since the forum software is so “smart” as to have come up with a fancier way for us to express things and change those for us lest we (God forbid) resort to plain old ASCII single or double-quote characters), and still nothing happens.

So for now looks like KB4MDD’s solution is the only one that works. Though FYI while that solution does properly enable the DTMF command to announce the IP, the command may just say “zero” when called from startup_macro if the node uses DHCP since the node may not get the IP address assigned until a few seconds after bootup. (And using a static IP configuration would not work on various hotspots you do not manage and there would be no point in saying the IP if it was static and thus already known.) But the important thing is to have the DTMF command which can be executed when needed. Having it also say it at boot or after the DHCP address is assigned is not really necessary.

Not sure why you can’t get mine to work since I’ve been using it for more than 10 years.
With exception to the startupmacro, which works slightly different than a normal macro. syntax

Hi Mike, I tried the first suggested solution first and it did what I needed so did not then also try what you proposed. Danny’s solution is pretty simple as it requires creating just one file and adding one line to rpt.conf. And I like that it gets the IP using the Linux ‘ip’ command rather than making a curl call to an external API. An important distinction here is if we want the LAN or WAN IP. Generally the LAN IP is what’s needed so you can then connect to the node from the same network from a phone or laptop browser or other app. The WAN IP would only be of interest if the network was forwarding the right ports to the node and we wanted to access it remotely, but in that case it might be easier to use a DDNS service. So in general my question relates to the best way to get the LAN IP, but a second command to get the WAN IP could also be useful.

It seems there ought to be an even simpler solution that takes the best parts of what you and Danny suggested. I wonder if the SayAlpha function could be used directly in rpt.conf in a DTMF command definition? If so the command definition could just pass the LAN IP to SayAlpha(). Seems there is not a lot of good info online as far as an Asterisk guide that explains what functions are available within each of the various .conf files.


I did some experimentation with the conf files and found another option using a very simple bash script to get the LAN IP. This is not really any simpler than Danny’s solution but the bash file is much simpler.

  1. Add below under [functions] section in rpt.conf:
    69 = autopatchup,context=my-ip,noct=1,farenddisconnect=1,dialtime=9000,quiet=1

  2. Update below section in extensions.conf:
    [my-ip]
    exten = 0,1,AGI(getip.sh)
    exten = 0,2,Wait,1
    exten = 0,3,SayAlpha(${result})
    exten = 0,4,Hangup

  3. Create file /var/lib/asterisk/agi-bin/getip.sh with below lines and chmod file to 775:

#!/bin/bash
echo SET VARIABLE result `hostname -I`
  1. Update modules.conf:
    load => res_agi.so.

Command *690 then says the IP Address. This is not necessarily any better of a solution but just thought I would post it in case anyone’s interested. The AGI function appears to provide a nice and secure way to retrieve data from the shell.

This can be extended to also provide the WAN address by adding Mike’s suggestion, so *690 gives the LAN IP and *691 gives the WAN IP.
[my-ip]

exten = 1,1,Set(result=${CURL(https://api.ipify.org)})
exten = 1,2,Wait,1
exten = 1,3,SayAlpha(${result})
exten = 1,4,Hangup

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