Created
March 27, 2009 13:46
-
-
Save bakkdoor/86698 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
%% | |
%% simple portscanner written in simple erlang :) | |
%% | |
-module(portscanner). | |
-export([start/0]). | |
-author({"Christopher Bertels", "[email protected]"}). | |
%% 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. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment