[#65] adding IP to the Information struct

This commit is contained in:
Felipe Ripoll 2018-07-18 11:22:50 -06:00
parent edea8086c4
commit fe95cd4f2b
1 changed files with 14 additions and 0 deletions

View File

@ -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)