Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Make the ping interval configurable

  • Loading branch information...
commit 081ec7c20f1173e003c7dd7789bb0f4000b13c14 1 parent 5a581a2
@msantos authored
Showing with 13 additions and 10 deletions.
  1. +1 −1  src/spood.erl
  2. +12 −9 src/spood_pinger.erl
View
2  src/spood.erl
@@ -46,7 +46,7 @@ start(Options) ->
spood_spoof:start_link(Dev, {Smac,Saddr}, {Dmac, Daddr}),
spood_dns:start_link(),
- spawn(spood_pinger, start, [Dev]),
+ spawn(spood_pinger, start, [Dev, timer:minutes(15)]),
spood_snuff:start_link(Dev, Daddr).
nameserver() ->
View
21 src/spood_pinger.erl
@@ -30,15 +30,18 @@
%% POSSIBILITY OF SUCH DAMAGE.
-module(spood_pinger).
--export([start/1]).
+-export([start/1, start/2]).
-export([range/2]).
--define(INTERVAL, 15*60000). % 15 minute
+-define(INTERVAL, 15*60000). % 15 minutes
%% Populate the local ARP cache by periodically scanning the network
-start(Dev) when is_binary(Dev) ->
- start(binary_to_list(Dev));
-start(Dev) when is_list(Dev) ->
+start(Dev) ->
+ start(Dev, ?INTERVAL).
+
+start(Dev, Interval) when is_binary(Dev) ->
+ start(binary_to_list(Dev), Interval);
+start(Dev, Interval) when is_list(Dev), Interval > 0 ->
{ok, Ifs} = inet:getifaddrs(),
Cfg = proplists:get_value(Dev, Ifs),
@@ -51,7 +54,7 @@ start(Dev) when is_list(Dev) ->
{active, false}
]),
- poll(Socket, ipv4_to_int(Network)+1, ipv4_to_int(Broadcast)).
+ poll(Socket, Interval, ipv4_to_int(Network)+1, ipv4_to_int(Broadcast)).
range({A1,A2,A3,A4}, {M1,M2,M3,M4}) ->
Addr = (A1 bsl 24) bor (A2 bsl 16) bor (A3 bsl 8) bor A4,
@@ -67,10 +70,10 @@ ipv4_to_int({A,B,C,D}) ->
<<N:4/unsigned-integer-unit:8>> = <<A, B, C, D>>,
N.
-poll(Socket, Start, End) ->
+poll(Socket, Interval, Start, End) ->
scan(Socket, Start, End),
- timer:sleep(?INTERVAL),
- poll(Socket, Start, End).
+ timer:sleep(Interval),
+ poll(Socket, Interval, Start, End).
scan(Socket, Address, End) when Address < End ->
Port = crypto:rand_uniform(16#0FFF, 16#FFFF),
Please sign in to comment.
Something went wrong with that request. Please try again.