[x]
Posted via EE Mobile

Search, ask, and monitor your questions on the go with EE Mobile. Visit Experts Exchange from your mobile device and never be out of touch again.

Question
[x]
Attachment Details
[x]
The Solution Rating System

With so many solutions, how can you tell which solutions are most likely to help you and which ones are not? To provide you with a tool to use, we rate our solutions based on various elements that most accurately determine if a solution is a quality solution. To explain what factors affect the solution rating, here are the elements we take into consideration when formulating our solution rating.

  • The Grade of the Solution
  • The Zone Rank of the Expert Providing the Solution
  • The Number of Author and Expert Comments
  • The Number of Experts Contributing
  • The Feedback of the Community

Your Input Matters
Because of the way the system is set up, the most important variable in this equation is you. As a member of Experts Exchange, you are able to cast your vote on the quality of the solutions in regard to how complete, accurate, helpful and easy to understand each solution is. When you provide your feedback, each rating is adjusted accordingly. So, if you see a solution that has a poor rating that you think is a good solution, let us know by rating it. As you do, the rating will be adjusted and will become more accurate for other members of our site.

If you have any suggestions that you would like to make for our rating system, please ask a question in the Suggestions Zone of Community Support.

Thank you!

9.7

Ping result missing some failures

Asked by mikelittlewood in Delphi Programming

Tags: Delphi 7

I have written a very small ping wild card application that will search an entire range of ip's, i.e. 192.168.0.x so it will ping from 192.168.0.0 to 192.168.0.254 and tell me whether it is getting a response or not and hen if it does it does a reverse dns lookup.

My problem is that the result is sometimes incorrect for a specific scenario.
I only thought I would expect a pass or fail but it seems that is counts a TTL expired in transit response as a pass, obviously because of the simple method I am using, or a return value I dont know to check.

Below is a copy of the unit of code I am using, and I just call ping( 192.168.0.0)
The result obviously comes from result := ( DW <> 0);
Is there anything else I can check?

As for some more information
A valid ping response looks like this

Pinging 192.168.0.0 with 32 bytes of data:

Reply from 192.168.0.0: bytes=32 time=6ms TTL=255
Reply from 192.168.0.0: bytes=32 time=1ms TTL=255
Reply from 192.168.0.0: bytes=32 time=4ms TTL=255
Reply from 192.168.0.0: bytes=32 time=1ms TTL=255

Ping statistics for 192.168.0.0:
    Packets: Sent = 4, Received = 4, Lost = 0 (0% loss),
Approximate round trip times in milli-seconds:
    Minimum = 1ms, Maximum = 6ms, Average = 3ms

and an invalid one looks might look like this:

Pinging 192.168.0.1 with 32 bytes of data:

Request timed out.
Request timed out.
Request timed out.
Request timed out.

Ping statistics for 192.168.0.1:
    Packets: Sent = 4, Received = 0, Lost = 4 (100% loss),


or look like this

Pinging 192.168.0.2 with 32 bytes of data:

Reply from 192.168.0.2: TTL expired in transit.
Reply from 192.168.0.2: TTL expired in transit.
Reply from 192.168.0.2: TTL expired in transit.
Reply from 192.168.0.2: TTL expired in transit.

Ping statistics for 192.168.0.2:
    Packets: Sent = 4, Received = 4, Lost = 0 (0% loss),
Approximate round trip times in milli-seconds:
    Minimum = 0ms, Maximum = 0ms, Average = 0ms
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
40:
41:
42:
43:
44:
45:
46:
47:
48:
49:
50:
51:
52:
53:
54:
55:
56:
57:
58:
59:
60:
61:
62:
63:
64:
65:
66:
67:
68:
69:
70:
71:
72:
73:
74:
75:
76:
77:
78:
79:
80:
81:
82:
83:
84:
85:
86:
87:
88:
89:
90:
91:
92:
93:
94:
95:
96:
97:
98:
99:
100:
101:
102:
103:
104:
105:
106:
107:
108:
109:
110:
111:
112:
113:
114:
115:
116:
117:
118:
119:
120:
121:
122:
123:
124:
125:
126:
127:
128:
129:
130:
131:
unit raw_ping;
 
interface
 
uses
   Windows, SysUtils, Classes;
 
type
   TSunB = packed record
      s_b1, s_b2, s_b3, s_b4: byte;
   end;
 
   TSunW = packed record
      s_w1, s_w2: word;
   end;
 
   PIPAddr = ^TIPAddr;
   TIPAddr = record
      case integer of
         0: (S_un_b: TSunB);
         1: (S_un_w: TSunW);
         2: (S_addr: longword);
      end;
 
 IPAddr = TIPAddr;
 
function IcmpCreateFile: THandle; stdcall; external 'icmp.dll';
function IcmpCloseHandle( icmpHandle : THandle) : boolean; stdcall; external 'icmp.dll'
function IcmpSendEcho( IcmpHandle : THandle; DestinationAddress : IPAddr;
                       RequestData : Pointer; RequestSize : Smallint;
                       RequestOptions : pointer;
                       ReplyBuffer : Pointer;
                       ReplySize : DWORD;
                       Timeout : DWORD) : DWORD; stdcall; external 'icmp.dll';
 
 
function Ping(InetAddress : string) : boolean;
 
procedure TranslateStringToTInAddr( AIP: string; var AInAddr);
 
implementation
 
uses
   WinSock;
 
function Fetch( var AInput: string; const ADelim: string = ' ';
                const ADelete: Boolean = true): string;
var
  iPos: Integer;
begin
   if ADelim = #0 then
   begin
      // AnsiPos does not work with #0
      iPos := Pos(ADelim, AInput);
   end else
      begin
         iPos := Pos(ADelim, AInput);
      end;
 
   if iPos = 0 then
   begin
      Result := AInput;
 
      if ADelete then
      begin
         AInput := '';
      end;
   end else
      begin
         result := Copy(AInput, 1, iPos - 1);
         if ADelete then
         begin
            Delete(AInput, 1, iPos + Length(ADelim) - 1);
         end;
      end;
end;
 
procedure TranslateStringToTInAddr(AIP: string; var AInAddr);
var
   phe: PHostEnt;
   pac: PChar;
   GInitData: TWSAData;
begin
   WSAStartup($101, GInitData);
   try
      phe := GetHostByName(PChar(AIP));
      if Assigned(phe) then
      begin
         pac := phe^.h_addr_list^;
         if Assigned(pac) then
         begin
            with TIPAddr(AInAddr).S_un_b do
            begin
               s_b1 := Byte(pac[0]);
               s_b2 := Byte(pac[1]);
               s_b3 := Byte(pac[2]);
               s_b4 := Byte(pac[3]);
            end;
         end else
            begin
               raise Exception.Create('Error getting IP from HostName');
            end;
      end else
         begin
            raise Exception.Create('Error getting HostName');
         end;
   except
      FillChar(AInAddr, SizeOf(AInAddr), #0);
   end;
   WSACleanup;
end;
 
function Ping( InetAddress : string) : boolean;
var
   handle: THandle;
   inAddr: IPAddr;
   DW: DWORD;
   rep: array[ 1..128] of byte;
begin
   result := false;
   handle := IcmpCreateFile;
   if handle = INVALID_HANDLE_VALUE then
      exit;
 
   translateStringToTInAddr( inetAddress, inAddr);
   DW := icmpSendEcho( handle, inAddr, nil, 0, nil, @rep, 128, 0);
   result := ( DW <> 0);
   icmpCloseHandle(Handle);
end;
 
end.
[+][-]06/19/08 11:21 AM, ID: 21824883Accepted Solution

View this solution now by starting your 30-day free trial. Setting up your free trial is quick, easy, and secure. We will return you to this solution, unlocked, when you're done.

About this solution

Zone: Delphi Programming
Tags: Delphi 7
Sign Up Now!
Solution Provided By: rllibby
Participating Experts: 2
Solution Grade: A
 
[+][-]06/18/08 02:16 AM, ID: 21811204Expert Comment

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 30-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]06/18/08 02:38 AM, ID: 21811301Author Comment

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 30-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]06/18/08 04:14 AM, ID: 21811668Author Comment

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 30-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]06/18/08 05:31 AM, ID: 21812106Assisted Solution

Assisted solutions are selected by the member who asked the question as a comment that contributed to their question's solution.

Start your 30-day free trial to view this Assisted Solution or ask the Experts your question.

 
[+][-]06/18/08 05:33 AM, ID: 21812117Expert Comment

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 30-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]06/18/08 08:16 AM, ID: 21813813Expert Comment

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 30-day free trial to view this Expert Comment or ask the Experts your question.

 
 
Loading Advertisement...
20091118-EE-VQP-93 / EE_QW_2_20070628