feat: add port check

This commit is contained in:
U-JOHNLIU\jonhl 2022-03-10 10:28:45 +08:00
parent db709fa9c8
commit 9ae3fe32fa
2 changed files with 23 additions and 1 deletions

View File

@ -109,6 +109,8 @@
, get_ipv6/1
, trim_string/1
, get_url_path/1
, get_ports/0
, check_port/1
]).
-define(TIMEZONE, + 8).
@ -890,3 +892,23 @@ url_path(Url) ->
%% "192.168.0.183:5094/wordServer/20211112142832/1.jpg",
{match, [{Start, _Len}]} = re:run(Url, <<"\/">>),
to_binary(string:substr(Url, Start + 1, length(Url))).
get_ports() ->
lists:foldl(fun(X, Acc) ->
case inet:port(X) of
{ok, Port} ->
Acc ++ [Port];
_ ->
Acc
end
end, [], erlang:ports()).
check_port(Port) ->
lists:any(fun(X) ->
case inet:port(X) of
{ok, Port} ->
true;
_ ->
false
end
end, erlang:ports()).

View File

@ -54,7 +54,7 @@ handle_info({message, #{<<"cmd">> := <<"LOGIN">>, <<"addr">> := Addr}}, #{<<"pro
Auto andalso erlang:send_after(5000, self(), check),
{ok, State#{<<"addr">> => Addr}};
handle_info({message, #{<<"cmd">> := <<"HEART">>}}, #{ <<"addr">> := Addr, <<"productId">> := ProductId, <<"channelId">> := ChannelId, <<"auto">>:= Auto} = State) ->
handle_info({message, #{<<"cmd">> := <<"HEART">>}}, #{ <<"addr">> := Addr, <<"productId">> := ProductId, <<"channelId">> := ChannelId} = State) ->
dgiot_bridge:send_log(ChannelId, ProductId, "DTU ~p HEART", [Addr]),
{ok, State};