1 | program Scan;
|
---|
2 |
|
---|
3 | {$APPTYPE CONSOLE}
|
---|
4 |
|
---|
5 | uses SysUtils, IPUtils, PingThread;
|
---|
6 |
|
---|
7 | var i,j:Cardinal;
|
---|
8 | Ping:Array of TPingResult;
|
---|
9 | PingCount,Cardinal1,Cardinal2:Cardinal;
|
---|
10 | Puffer:String;
|
---|
11 | ThreadArray:Array of TPingThread;
|
---|
12 | ThreadsComplete:Boolean;
|
---|
13 | begin
|
---|
14 | WriteLn;
|
---|
15 | WriteLn('Scan v1.0');
|
---|
16 | WriteLn('Synapse Demo Application');
|
---|
17 | WriteLn('(c)2003 by Christian Brosius');
|
---|
18 | WriteLn;
|
---|
19 | if (ParamCount = 2)and // Parse Commandline
|
---|
20 | (IsIPAdress(ParamStr(1)))and
|
---|
21 | (IsIPAdress(ParamStr(2)))
|
---|
22 | then
|
---|
23 | begin
|
---|
24 | Cardinal1 := IPToCardinal(StrToIP(ParamStr(1)));
|
---|
25 | Cardinal2 := IPToCardinal(StrToIP(ParamStr(2)));
|
---|
26 | // Count of Adresses to ping
|
---|
27 | PingCount := (Cardinal2 - Cardinal1) + 1;
|
---|
28 |
|
---|
29 | // Show Adresscount to User
|
---|
30 | Write('Pinging ' + IntToStr(PingCount) + ' Adresses');
|
---|
31 | // Initialize dyn. Arrays
|
---|
32 | SetLength(Ping,PingCount);
|
---|
33 | SetLength(ThreadArray,PingCount);
|
---|
34 | j := 0;
|
---|
35 | for i := Cardinal1 to Cardinal2 do
|
---|
36 | begin
|
---|
37 | Ping[j].IPAdress := IPToStr(CardinalToIP(i));
|
---|
38 | Ping[j].Exists := false;
|
---|
39 | Inc(j);
|
---|
40 | end;
|
---|
41 |
|
---|
42 | // Create one Thread for each Ping
|
---|
43 | for i := 0 to PingCount-1 do
|
---|
44 | begin
|
---|
45 | ThreadArray[i] := TPingThread.Create(Ping[i]);
|
---|
46 | end;
|
---|
47 |
|
---|
48 | Write(' ');
|
---|
49 |
|
---|
50 | // Wait till all threads are executed
|
---|
51 | repeat
|
---|
52 | ThreadsComplete := true;
|
---|
53 | Write('.');
|
---|
54 | Sleep(1000);
|
---|
55 | for i := 0 to PingCount-1 do
|
---|
56 | begin
|
---|
57 | if not ThreadArray[i].Ready
|
---|
58 | then
|
---|
59 | begin
|
---|
60 | ThreadsComplete := false;
|
---|
61 | break;
|
---|
62 | end;
|
---|
63 | end;
|
---|
64 | until ThreadsComplete;
|
---|
65 |
|
---|
66 | WriteLn;
|
---|
67 | WriteLn;
|
---|
68 |
|
---|
69 | // Show Results to User
|
---|
70 | for i := 0 to PingCount-1 do
|
---|
71 | begin
|
---|
72 | if ThreadArray[i].PingResult.Exists
|
---|
73 | then
|
---|
74 | begin
|
---|
75 | Puffer := IntToStr(i+1) + ' ' + ThreadArray[i].PingResult.IPAdress;
|
---|
76 | WriteLn(Puffer);
|
---|
77 | end;
|
---|
78 | end;
|
---|
79 |
|
---|
80 | // Free Threads
|
---|
81 | for i := 0 to PingCount-1 do
|
---|
82 | begin
|
---|
83 | ThreadArray[i].Free;
|
---|
84 | end;
|
---|
85 | end
|
---|
86 | else
|
---|
87 | begin
|
---|
88 | WriteLn('Syntax: Scan StartIP StopIP');
|
---|
89 | WriteLn;
|
---|
90 | WriteLn('Description:');
|
---|
91 | WriteLn(' With Scan you can do a very fast scan of Adresses on your Network-Segment.');
|
---|
92 | WriteLn;
|
---|
93 | WriteLn('Example: scan 192.168.50.1 192.168.50.254');
|
---|
94 | end;
|
---|
95 | end.
|
---|