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 don't fully understand what you are trying to do. Can you give a real example of what you are trying to match against what?
Yes i can!
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 !
url: msg.ip_websvr + msg.webnaam,
You could parse the result of the
nslookup command, using an exec node, or you could use the nslookup module.
Or you read and parse
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 "_"
now get this value in NR and strip it...
You could read the file in node red and parse it there, if that is easier.
will try that too
this what i got for now: and it gives the right record.
- Only have to strip the hostname from it...
instead of 192.168.20.48
var searchitem = "domserver"
var cmd = "grep " + searchitem + " /etc/hosts "
if (searchitem.includes("_") === false)
cmd = cmd + " | grep -v " + '"_"'
and the code to remove the tab
test = msg.payload
myArray = test.split('\t')
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!
json.txt (2.2 KB)
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.
This topic was automatically closed 60 days after the last reply. New replies are no longer allowed.