Powered by AppSignal & Oban Pro
Would you like to see your link here? Contact us

My IP Info

myip.livemd

My IP Info

Mix.install([
  {:req, "~> 0.3.0"},
  {:floki, "~> 0.35.2"},
  {:kino_maplibre, "~> 0.1.10"}
])

Section

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()
ip_info = Req.get!("https://ipinfo.io/#{ip_address}/geo").body
coords =
  ip_info
  |> Map.get("loc")
  |> String.split(",")
  |> Enum.map(fn x ->
    {value, _} = Float.parse(x)
    value
  end)
  |> Enum.reverse()
  |> List.to_tuple()
MapLibre.new(style: :street, center: coords, zoom: 10)