Use Livebook to open this notebook and explore new ideas.
It is easy to get started, on your machine or the cloud.
# My IP Info
```elixir
Mix.install([
{:req, "~> 0.3.0"},
{:floki, "~> 0.35.2"},
{:kino_maplibre, "~> 0.1.10"}
])
```
## Section
```elixir
html = Req.get!("http://checkip.dyndns.org").body
ip_address =
html
|> Floki.parse_document!()
|> Floki.find("body")
|> Floki.text()
|> String.replace("Current IP Address:", "")
|> String.trim()
```
```elixir
ip_info = Req.get!("https://ipinfo.io/#{ip_address}/geo").body
```
```elixir
coords =
ip_info
|> Map.get("loc")
|> String.split(",")
|> Enum.map(fn x ->
{value, _} = Float.parse(x)
value
end)
|> Enum.reverse()
|> List.to_tuple()
```
```elixir
MapLibre.new(style: :street, center: coords, zoom: 10)
```
See source