LAN Web TCP Delphi

//bu thread i kullanarak ip scanner yapabilirsiniz...
unit IPScanner;
interface
uses
Windows, Classes, ScktComp;
type
TScannerThread = class(TThread)
private
Socket: TClientSocket;
protected
procedure Execute; override;
public
constructor Create(Address: string; Port: integer);
destructor Destroy; override;
end;
TScanner = class(TObject)
private
ScannerThread: TScannerThread;
public
CurrentAddress: string;
Addresses: string;
TimeOut: integer;
procedure StartScan(sStart, sEnd: string; iPort, iDelay, iTimeOut: integer);
procedure StopScan;
procedure AddAddress(Address: string);
end;
var
Scanner: TScanner;
Scanning: boolean;
Update: TRTLCriticalSection;
threadvar
Connected: boolean;
implementation
function StrToInt(S: string): integer;
var
V, Code: integer;
begin
Val(S, V, Code);
Result := V;
end;
function IntToStr(X: integer): string;
var
S: string;
begin
Str(X, S);
Result := S;
end;
function Split(Input: string; Deliminator: string; Index: integer): string;
var
StringLoop, StringCount: integer;
Buffer: string;
begin
StringCount := 0;
for StringLoop := 1 to Length(Input) do
begin
if (Copy(Input, StringLoop, 1) = Deliminator) then
begin
Inc(StringCount);
if StringCount = Index then
begin
Result := Buffer;
Exit;
end
else
begin
Buffer := '';
end;
end
else
begin
Buffer := Buffer + Copy(Input, StringLoop, 1);
end;
end;
Result := Buffer;
end;
function NextAddress(Address: string): string;
var
Octet1, Octet2, Octet3, Octet4: integer;
begin
Octet1 := StrToInt(Split(Address, '.', 1));
Octet2 := StrToInt(Split(Address, '.', 2));
Octet3 := StrToInt(Split(Address, '.', 3));
Octet4 := StrToInt(Split(Address, '.', 4));
Inc(Octet4);
if Octet4 >= 256 then
begin
Octet4 := 1;
Inc(Octet3);
end;
if Octet3 >= 256 then
begin
Octet3 := 1;
Inc(Octet2);
end;
if Octet2 >= 256 then
begin
Octet2 := 1;
Inc(Octet1);
end;
if Octet1 >= 256 then
begin
Octet1 := 1;
Inc(Octet4);
end;
Result := IntToStr(Octet1) + '.' + IntToStr(Octet2) + '.' + IntToStr(Octet3) + '.' + IntToStr(Octet4);
end;
procedure TScanner.StartScan(sStart, sEnd: string; iPort, iDelay, iTimeOut: integer);
begin
CurrentAddress := sStart;
TimeOut := iTimeOut;
Scanning := True;
while Scanning do
begin
CurrentAddress := NextAddress(CurrentAddress);
ScannerThread := TScannerThread.Create(CurrentAddress, iPort);
if CurrentAddress = sEnd then StopScan;
Sleep(iDelay);
end;
end;
procedure TScanner.StopScan;
begin
Scanning := False;
end;
procedure TScanner.AddAddress(Address: string);
begin
Addresses := Addresses + Address + #13#10;
end;
constructor TScannerThread.Create(Address: string; Port: integer);
begin
inherited Create(False);
Socket := TClientSocket.Create(nil);
Socket.Host := Address;
Socket.Port := Port;
Socket.ClientType := ctBlocking;
FreeOnTerminate := True;
end;
destructor TScannerThread.Destroy;
begin
inherited;
Socket.Free;
end;
procedure TScannerThread.Execute;
var
TimeOut: integer;
begin
TimeOut := 0;
try
Socket.Active := True;
while ((TimeOut) < (Scanner.TimeOut div 100)) do
begin
if Socket.Socket.Connected then
begin
Connected := True;
Break;
end;
Sleep(100);
Inc(TimeOut);
end;
except
end;
if Connected then
begin
EnterCriticalSection(Update);
try
Scanner.AddAddress(Socket.Host);
finally
LeaveCriticalSection(Update);
end;
end;
end;
initialization
InitializeCriticalSection(Update);
finalization
DeleteCriticalSection(Update);
end.