bartblast

bartblast

Creator of Hologram

How to resolve IP address given a URL

Does anyone know whether it’s possible in HTTPoison or Hackney to return the resolved IP address of the given URL in the response?

If it’s not possible, how can I do this?
I tried :inet.getaddr(“https://www.google.com”, :inet) but it always returns {:error, :einval} …

Most Liked

l00ker

l00ker

Leave off the protocol (http://) and use single quotes around the domain like:
:inet.getaddr('www.google.com', :inet)

Marcus

Marcus

The function just need the hostname:

iex(11)> :inet.getaddr('www.google.com', :inet)
{:ok, {142, 250, 185, 100}}
hubertlepicki

hubertlepicki

It returns error because you are passing an Elixir String / Binary, while it is an Erlang function expecting argument which is Charlist.

These two types are not directly compatible and you have to convert between these two often when using Erlang libraries from Elixir. Generally charlists literals will be wrapped in single quotes ’ and binaries with double quotes ". You can convert between these with to_charlist and to_string functions that are imported by default everywhere.

So, your example will work if you use single quotes and skip https:// which is a protocol. You should write:

:inet.getaddr('google.com', :inet)
{:ok, {172, 217, 16, 14}}
bartblast

bartblast

Creator of Hologram

Awesome, it works - yeah the problem was string instead of charlist. Looks like I need to improve my Erlang knowledge… Thanks @l00ker, @Marcus, @hubertlepicki !

Where Next?

Popular in Questions Top

JDanielMartinez
Hi! May someone helps me, please! I have two apps into an umbrella project: the first one is Database, which manages queries, and the se...
New
senggen
Erlang/OTP 25 [erts-13.2.2] [source] [64-bit] [smp:8:8] [ds:8:8:10] [async-threads:1] 15:22:35.803 [error] gen_event {lager_file_backend...
New
sergio
In Ruby, I can go: User.find_by(email: "foobar@email.com").update(email: "hello@email.com") How can I do something similar in Elixir? ...
New
albydarned
Hello all! I am typing this post from my new MacBook Pro with the M1 chip. I’m loving it so far, and will probably use it as my daily dr...
New
_russellb
I want to try my hand at web scraping. What tools/libraries do I need to use. I’m hoping to turn this into something professional so don’...
New
Harrisonl
We have an ECS cluster with 4 services, where each task joins a single cluster, via discovery ECS discovery service. Currently when I de...
New
rms.mrcs
Hi, I need to transform a list of numbers into a map where the keys are the indexes and the values are the original values of the list....
New
chewm
Hi guys, nice to meet you to the whole forum, I’m new here, I’m trying to configure visual studio code for elixir, right now the intellis...
New
wernerlaude
In AR this is so simple @articles = current_user.articles How to do in Ecto? def index(conn, _params) do current_user = conn.assig...
New
joeerl
Hello again - after a longish gap I’ve decided I really must dig into Elixir and see what’s been happening here - so I have a few questio...
New

Other popular topics Top

Tee
can someone please explain to me how Enum.reduce works with maps
New
vonH
In asking this question I am more interested about the expressiveness of the language itself and less concerned about the availability of...
New
axelson
This post is a wiki (feel free to hit the edit button near the bottom right of this post to add your own changes!) This post collects co...
239 45766 226
New
_russellb
I want to try my hand at web scraping. What tools/libraries do I need to use. I’m hoping to turn this into something professional so don’...
New
Harrisonl
We have an ECS cluster with 4 services, where each task joins a single cluster, via discovery ECS discovery service. Currently when I de...
New
fayddelight
I tried installing elixir 1.11.2 erlang 23.3.4 via asdf in my zsh shell. Enabled the versions locally and globally. When I list them ...
New
electic
Hi, I am new to Elixir. I am trying to use the DateTime component to insert a date into MySQL however the there seems to be no way to fo...
New
chrisalley
ExUnit now has describe blocks which is a welcome addition coming from RSpec. In the docs, it states that nested hierarchies of describe ...
New
Patoshizzle
After calling mix ecto.create I get this error: 17:00:32.162 [error] GenServer #PID<0.412.0> terminating ** (Postgrex.Error) FATAL...
New
Nvim
Elixir appears to be a superior language to Python. I don’t see any advantage of Python over Elixir. Are there any?
New

We're in Beta

About us Mission Statement