Erlang: Read the IP address
source link: https://www.codesd.com/item/erlang-read-the-ip-address.html
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
Erlang: Read the IP address
I'm trying to get my IP address using Erlang.
I found this example from here: Erlang: Finding my IP Address
local_ip_v4() ->
{ok, Addrs} = inet:getifaddrs(),
hd([Addr || {_, Opts} <- Addrs, {addr, Addr} <- Opts, size(Addr) == 4, Addr =/= {127,0,0,1}]).
But it returns a value like this: {127,0,0,1}
I want it to return a value like this: "{127,0,0,1}"
with double quotes (""
) because I want to use re:replace
to change ,
to .
.
How can I do that?
The function returns the tuple because this is something that erlang code can handle natively. What you might want to do is transform this tuple to a string and then apply string operations. Details on how to do that can be found e.g. at Convert erlang terms to string, or decode erlang binary
Related Articles
Read the MAC address of the network card in .NET
Read the IP address of the text file to IPTABLES
Read the IP address from a text file in C
How to read the IP address of the default Windows gateway in C ++
How to build a string by reading the IP address of a file in a shell script?
socket - read the IP address of the terminal
Reading the email address of the contacts fails with a strange memory problem
Read the IP address of the file
Why the processor only reads the aligned addresses
API based on the IP address of the user
Read the XDATA value to the application in CC2541
XMLReader reading the XML file based on the value of the attribute
Linux TCP Server: read the client IP address before accepting the connection
Read the 16-bit small-enunci, then analyze as a bittring in erlang
Recommend
About Joyk
Aggregate valuable and interesting links.
Joyk means Joy of geeK