How to get erlang node IP address?

Is there an easy way to get the IP address of a connected erlang node? I would like to initiate an SCTP connection with several nodes, and because of how the system was designed, the knowledge that I have about them is only their atom node ().

More precisely, I am wondering if there is any API provided by Erlang (or some derived method) that allows you to get the IP address of a node given its atom () identifier.

+7
source share
3 answers

You can use the rpc module to call a function on an external node

Example:

rpc:call(Node,inet,getif,[]) 

note: this only works on nodes that are already connected through the erlang distribution

+4
source

I solved this problem by running the process on node and receiving a message about sending a message containing its IP addresses. If anyone knows a more elegant solution, I would like to hear it.

The command I used to get the address after starting the node process was this: inet:getif() . Keep in mind that the result of this command includes the return address.

Keep in mind that each node can have several IP addresses, and the SCTP server may not listen to all of them.

Another idea that I was thinking about trying is to convert the atom returned from node () to a string, parse the string to get the host name, and do a DNS lookup. It might work, but I never tried. The DNS lookup result must be cached, so there may not be a round-trip network. Also, I really hate to suggest anything about returning an atom from node ().

+2
source

It seems that net_kernel:nodes_info() - for all nodes - and net_kernel:node_info(Node) for one node - contains this information, etc., although this does not seem to be a publication on the manual page. This seems like a better solution in some way, because it will also work with things like Java and C nodes that you cannot send functions to.

+2
source

All Articles