6

Erlang: Read the IP address

 2 years ago
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

advertisements

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

I'd like to be able to read the mac address from the first active network adapter using VB.net or C# (using .NET 3.5 SP1) for a winform applicationSince .Net 2.0 there's been a NetworkInterface class in the System.Net.NetworkInformation namespace tha

Read the IP address of the text file to IPTABLES

Currently I am using ufw to manually add the ip rules by typing sudo ufw allow from (my ip address) I have retrieve the ip address of my client ip by doing some script calling from my database and save it to a .txt file. this is the value i get ipadd

Read the IP address from a text file in C

I have a text file(IP_CONFIG.txt) containing an IP address like this CS 192.168.128.3 PORT 1111 i want to read the mentioned IP in the text file in my C code with a parameter. My code looks like this <<header files>> #define ROW 11 #define COL

How to read the IP address of the default Windows gateway in C ++

Can some body point me how to read the default windows gateway IP address in C++. I am able to read the list of all the IP addresses using GetAdaptersInfo() but not the default gateway IP address. GetAdaptersInfo( pAdapterInfo, &BufferLength ); // It

How to build a string by reading the IP address of a file in a shell script?

I have a text file which will have IP Address like this - 1.2.3.4 4.5.6.67 9.10.23.40 11.12.3.4 4.15.16.67 19.10.23.40 Now I need to read the above text file and construct below sql string for each IP Address - As you can see, only the IP Address por

socket - read the IP address of the terminal

I'm reading addres from the terminal in this way to connect the client to a server, but I've been told that this is not correct because I should convert it through inet_pton function. Is this true? Can you explain me why? I'm doing tests with 127.0.0

Reading the email address of the contacts fails with a strange memory problem

I'm stumped. I'm trying to get a list of all the email address a person has. I'm using the ABPeoplePickerNavigationController to select the person, which all seems fine. I'm setting my ABRecordRef personDealingWith; from the person argument to - (BOO

Read the IP address of the file

Example 1 <?php function Piso() { $ip = '77.1.1.1.1'; $ip2 = $_SERVER['REMOTE_ADDR']; return ($ip == $ip2); } ?> Example 2 <?php function Piso() { $ip = fopen("bune.txt", "r"); $ip2 = $_SERVER['REMOTE_ADDR']; return ($ip == $i

Why the processor only reads the aligned addresses

So I was reading few articles (and few questions on StackOverflow) about memory alignment and I understood why structs like this: struct A { char c; int i; } will have padding. Also it is clear that fetches from not aligned memory will be slower if p

API based on the IP address of the user

I developed an API to get all the data. The site do not have a user registration system or anything to identify the user making a call to the API. If I could identify the user making the call, whenever someone misuse or attack the API I could even ba

Read the XDATA value to the application in CC2541

I want to read the MAC address for the Bluetooth LE chip CC2541. This is stored in memory location 0x780C. I went through the osal_snv_read function but I don't know what osalSnvId_t id is. A brief explanation about how this workds would be really he

XMLReader reading the XML file based on the value of the attribute

I am trying to read the following file, I can read the attributes, but I can't go into the specific element (Address in this case) and read its elements based on the attribute of that (Address) element. Shortly I need to distinguish between work and

Linux TCP Server: read the client IP address before accepting the connection

Related: C++ Winsock API how to get connecting client IP before accepting the connection? Hi, when you are running a TCP server (written in C, using the Berkeley Socket API) is it possible to read a client's IP address/port before actually accepting

Read the 16-bit small-enunci, then analyze as a bittring in erlang

I've inherited a binary file format with the following specification: | F | E | D | C | B | A | 9 | 8 | 7 | 6 | 5 | 4 | 3 | 2 | 1 | 0 0:| Status bit | ------ 15 - bit unsigned integer ----------- 1:| Status bit | ---- uint:10 ---- | ---- uint:5 ----

About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK