Recently, CallToPower has posted a simple portscanner written in Java. To make a small comparison, I wrote a version in Erlang. Since Java isn’t very well suited for parallel programming, I think my version should beat the one in Java. Maybe someone wants to make a real benchmark?
Heres the code:
%% %% simple portscanner written in simple erlang :) %% -module(portscanner). -export([start/0]). -author({"Christopher Bertels", "bakkdoor@flasht.de"}). %% start portscanner process. start() -> Host = io:get_line("host?\n") -- "\n", Start = list_to_integer(io:get_line("start port?\n") -- "\n"), End = list_to_integer(io:get_line("end port?\n") -- "\n"), io:format("host: ~s, start: ~p, end: ~p~n~n", [Host, Start, End]), start_threads(Host, Start, End). %% start End - Start threads, each connecting to each port in that range. start_threads(Host, Start, End) when Start > End -> io:format("started all scanning processes on ~p~n", [Host]); start_threads(Host, Start, End) when Start =< End -> spawn(fun() -> connect(Host, Start) end), start_threads(Host, Start + 1, End). %% connects to Host on Port and prints a message, if connetion works. connect(Host, Port) -> Connection = gen_tcp:connect(Host, Port, [binary, {packet, 0}]), case Connection of {ok, S} -> io:format(">> Port open ~s:~p~n", [Host, Port]), gen_tcp:close(S); _ -> none end. |


One Response
Stay in touch with the conversation, subscribe to the RSS feed for comments on this post.
Also wenigstens ist er um einiges kürzer
Mach mal echt nen benchmark, das würd mich interessieren!