Return IP from multiple NICs

I'm working on a solution in NodeRED where a Pi will be using Wifi for the internet and its ethernet port for a closed LAN. I'd like to be able to retrieve the current machine's IP address for both NICs in NodeRED.

I came across https://flows.nodered.org/node/node-red-contrib-ip, but upon more reading and testing, it only returns the Local IP of the NIC that is internet-facing.

I also came across this https://flows.nodered.org/flow/09e0f1a6b4446c214b1cb5c22f7c8d08, but my issue with that is that you have to already know the IP of a host on your LAN in order for the function to work properly. In my situation, I won't even always know if I'm in a 192, 10, or 17 IP range, let alone know the IP of a host to connect to.

Furthermore, I'm hoping to make a solution that requires no real input from the user. Just plug in and go.

Assume for this that there will always be a DHCP server handing out addresses on both networks.

Thanks!

You can use the ip command in an exec node to fetch the data you want. For example to get information on all interfaces (try these in a terminal first so you can see what you are dealing with)
ip address show
so you could run that and then parse the result to find what you want. Alternatively, to get the data for particular interfaces you can run
ip address show eth0
ip address show wlan0
You could do some of the parsing in the command, so to get the ip4 address (I guess you want that rather than ip6) for wlan0
ip address show wlan0 | grep "inet "
which should then be quite easy to extract the address from.
If you study the docs for the ip command there may well be options you can specify to home in on exactly what you want, there are lots of options and I don't know it well enough to say.

As a matter of interest, why do you need to know this?

I am developing a NodeRED based device that fetches information from the internet using various APIs and then passes along information to devices on a closed LAN.

The specific use case is basically taking in information like current weather/temperature, converting that information into OSC, and then sending it to a theatrical lighting control console to display.

I'll experiment with this, thanks!

But why do you need the ip addresses?

I need the ethernet IP address in order to tell my lighting console where to send commands, essentially I'm sending OSC from the lighting console to NodeRED with instructions on exactly what data I'm looking for. Then, NodeRED replies with the requested information.

So basically, my light board sends /weather/get/current=temperature

and then NodeRED replies with /weather/out/current/temperature=90.1

If I was only sending information in one direction, it wouldn't be important to know the pi's ethernet IP, but I need to specify the address on my lighting console.

The wifi address really doesn't matter - the issue I was having was that the existing nodes only returned the IP of the internet-facing connection.

Do you know the ip address of the console? If so, if you send it a message the console could extract the senders ip address automatically from the IP data. Alternatively you could poll the console to ask it what it needs so the comms is all one direction.
Yet again, if you have control of the console could you run an mqtt broker on it?
Loads of other alternatives, I imagine, that might make life simpler. You might be entirely happy with your current plan though, in which case please ignore me :slight_smile:

Unfortunately the console is pretty locked down, and while I could definitely do this on my own console here at home for my own purposes, I can't do it on consoles owned by others, which is 90% of the time. Typically whatever venue/theatre I'm working in owns their own console, I'm not bringing mine.

The OSC messages are being sent/received using UDP nodes in NodeRED - unfortunately in the console logs on the lighting console (that are available without needed to get under the hood) I only see the messages themselves and not any metadata about them.

The only way to see the information on the console log is if I initiate a TCP connection, which could certainly work, but there's benefit to NodeRED knowing its eth0 IP as well, because then I could display it on an LCD for the user, etc etc.

Have been experimenting with the terminal method you suggested, so far so good!

Using ip address show eth0 | grep "inet " in an exec node worked perfectly. Thanks so much for your help!

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