I am busy with an action to remove all ip-adresses from my code and use hostnames that are registrated in /etc/hosts.
This works for lot of code and nodes , but not always..
Now the problem.
I have a function node that looks for the local ip and the ip of the active flow.
When the subnet matches it adresses the msg via mqtt and otherwise it sends the msg with i http command to another servr. This works for years.
But now i use host name for the localadress and dns name for http adress and i cant matched thse two anymore...
Is there a way in NR to resolve
a) a host as pecified in /etc/hosts
b) dns name the main parts works ok!
I have a working flow that send msg to my nest hub (images).
You have to put these images first on a webserver.
You have to tell the nest hub where to find the images. That works great with for example
msg.ip_websvr = http://192.168.20.10/etc (see part of my msg (flow) below
But i want alle my used internal ip-adressen used by HOSTNAME which i declare in /etc/host in de docker or at the etc of the host, this works perfect voor 99% of my flows and other software.
BUT, my nest hub does not except local hostnames because it cannot resove it
msg.ip_websvr = http://domserver/etc
So i have to translate the hostname in msg.ip_websvr before sending it to the nesthub !
Could be a solution as the nodered docker node supports grep in the docker..
When i use this i get a line with the correct IP
grep domserver /etc/hosts | grep -v "_"
Problems solved!
I now can resolve an ipadres from a string with an hostname in it...
I had to use a smaal flow for it, and it would be more perfect if it was one procedure which i can reuse..
But, very hapy for now!
for those who can used it...
And thanks for the help!
Personally, I would do the hosts process when node-red starts and then maybe periodically - not doing it when you want to process the address - unless your hosts file is changing a lot.