From fe95cd4f2b749a3134f96599577258b3dd79d710 Mon Sep 17 00:00:00 2001 From: Felipe Ripoll Date: Wed, 18 Jul 2018 11:22:50 -0600 Subject: [PATCH] [#65] adding IP to the Information struct --- lib/poa_agent/entity/host/information.ex | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/lib/poa_agent/entity/host/information.ex b/lib/poa_agent/entity/host/information.ex index 5e8f1f9..2452642 100644 --- a/lib/poa_agent/entity/host/information.ex +++ b/lib/poa_agent/entity/host/information.ex @@ -12,6 +12,7 @@ defmodule POAAgent.Entity.Host.Information do net: Literal.Decimal.t(), protocol: pos_integer, api: Version.t(), + ip: String.t(), port: Literal.Decimal.t(), ## :inet.port_number() os: String.t(), os_v: Version.t(), @@ -27,6 +28,7 @@ defmodule POAAgent.Entity.Host.Information do :net, :protocol, :api, + :ip, :port, :os, :os_v, @@ -43,6 +45,7 @@ defmodule POAAgent.Entity.Host.Information do net: nil, protocol: nil, api: "", # this field belongs to JS version, doesn't make sense here + ip: ip(), port: "", # TODO os: os(), os_v: os_version(), @@ -51,6 +54,17 @@ defmodule POAAgent.Entity.Host.Information do } end + defp ip do + case :inet.getif() do + {:ok, [{ip, _, _} | _]} -> + ip + |> :inet_parse.ntoa + |> List.to_string + _ -> + "" + end + end + defp os do {_, os} = :os.type() Atom.to_string(os)