A ping program.

Hello dear people at embarcadero network, I am a student trying to learn Delphi on my own because my level of education given by my school is incredibly low.
My question is the following.

I whould like to make a program that ''pings'' a IP adresss and put out the the reponse time in the form, Also when there is no response a text saying "Online" should turn off to "offline"

I know this is probably a realy insane easy thing to do but i just started learning delphi.

//The Ping command should be under a timer i assume ''pinging'' the server every 5 seconds orso.
0
Tim
5/5/2010 8:58:30 AM
embarcadero.delphi.winsock 1874 articles. 2 followers. Follow

3 Replies
3596 Views

Similar Articles

[PageSpeed] 35

<Tim Verdonck> wrote in message news:239757@forums.embarcadero.com...

> I whould like to make a program that ''pings'' a IP adresss
> and put out the the reponse time in the form, Also when
> there is no response a text saying "Online" should turn
> off to "offline"

WinSock has no native pinging capabilities of its own.  You have to either 
implement the ICMP protocol manually (like Indy does in its TIdIcmpClient 
component), or use Microsoft's ICMP API instead 
(http://msdn.microsoft.com/en-us/library/aa915740.aspx).

-- 
Remy Lebeau (TeamB)
0
Remy
5/5/2010 5:40:38 PM
Hi, IdICMPClient will raise a socket error if you run it under a "limited Windows user", you must run under administrator.
Another code of Ping is here :

{code}
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';

// -----------------------------------------------------------------------------
procedure TranslateStringToTInAddr(AIP: String; var AInAddr);
var
  phe: PHostEnt;
  pac: PAnsiChar;
  GInitData: TWSAData;
begin
  WSAStartup($101, GInitData);
  try
    phe := GetHostByName(PAnsiChar(AnsiString(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; ATimeout: integer = 500) : 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,
        @data[1], Length(data),  // data and length
        nil, @rep, 128, ATimeOut);
  Result := (DW <> 0);
  IcmpCloseHandle(Handle);
end;
{code}
How to use :
{code}
var d: Cardinal;
d := GetTickCount();
if Ping('192.168.1.1') then <Reachable> else <Unreachable>
d := GetTickCount() - d;
Showmessage('Delay is ' + InttoStr(d) + ' ms');
{code}
icmp.dll is available in Windows
0
Nguyen
5/7/2010 2:41:04 AM
<Diep Thanh Nguyen> wrote in message news:240255@forums.embarcadero.com...

> Hi, IdICMPClient will raise a socket error if you run it
> under a "limited Windows user", you must run under
> administrator.

Yes.  That is because Indy uses direct RAW socket access to implement ICMP, 
but newer Windows versions restrict the use of RAW sockets.  That is why I 
mentioned Microsoft's ICMP API as an alternative.  Microsoft bypasses its 
own restrictions so that ICMP can work correctly in all user accounts.

> function IcmpCreateFile : THandle; stdcall; external 'icmp.dll';

The ICMP API is officially implemented in iphlpapi.dll under Windows XP 
onwards.  icmp.dll should only be used under Windows 2000 and earlier. 
Microsoft even says as much in the IcmpCreateFile() documentation:

{quote}
The IcmpCreateFile() function is exported from the Icmp.dll on Windows 2000. 
The IcmpCreateFile() function is exported from the Iphlpapi.dll on Windows 
XP and later. Windows version checking is not recommended to use this 
function. Applications requiring portability with this function across 
Windows 2000, Windows XP, Windows Server 2003 and later Windows versions 
should not statically link to either the Icmp.lib or the Iphlpapi.lib file. 
Instead, the application should check for the presence of IcmpCreateFile() 
in the Iphlpapi.dll with calls to LoadLibrary() and GetProcAddress(). 
Failing that, the application should check for the presence of 
IcmpCreateFile() in the Icmp.dll with calls to LoadLibrary() and 
GetProcAddress().
{quote}

> icmp.dll is available in Windows

For now.  It has been officially documented in MSDN for years that it would 
go away in a future OS version.

-- 
Remy Lebeau (TeamB)
0
Remy
5/7/2010 10:36:19 PM
Reply:

Similar Artilces:

ping ping ping ping
Are you guys getting pinged to hell tonight also? I must have been pinged thousands of times tonight "code_wrong" <tac@tac.ouch.co.uk> wrote in message news:bi69o7$4of$1@news.grc.com... > Are you guys getting pinged to hell tonight also? > I must have been pinged thousands of times tonight It's the Nachia / Welchia worm. "Big Tom" <unisteel_tom@hotmail.com> wrote in message news:bi69rv$4qg$1@news.grc.com... > "code_wrong" <tac@tac.ouch.co.uk> wrote in message > news:bi69o7$4of$1@news.grc.com... > > Are you g...

PING, PING, PING
What's the EASIEST way to code a PING method in .NET? I want to test if a W2K server is availble on the network in my asp.net application. Also, does anyone know how to test if a web service is available? (kinda a ping for a site)...

Win32 program: Delphi 7 vs Delphi XE5
How is a D7 Win32 program compared to a Delphi XE5 one in terms of stability and performance? Is Delphi XE5 good enough for a big ERP project with several DLL's and hundreds of units and forms? Thanks in advance Am 26.12.2013 15:02, schrieb lior ilan: > How is a D7 Win32 program compared to a Delphi XE5 one in terms of stability > and performance? > Is Delphi XE5 good enough for a big ERP project with several DLL's and > hundreds of units and forms? > Thanks in advance > Hello, XE5 has increased functionality. Stability seems to be ok for most ...

Ping
Frank, what happened to the schedule and inclusions of CAs? Is there any problem preventing us from continuing to process the CAs which are ready for the comments period? -- Regards Signer: Eddy Nigg, StartCom Ltd. Jabber: startcom@startcom.org Blog: https://blog.startcom.org On 10/29/2008 11:13 PM, Eddy Nigg: > Frank, what happened to the schedule and inclusions of CAs? Is there any > problem preventing us from continuing to process the CAs which are ready > for the comments period? > BTW, I'd like to propose to cut the comments period to one week, wit...

winsock programming
I hope someone will be able to help me. I am using PB10.5 build 4523 and I am trying to obtain the ip address and port of connected client socket uisng the winsock 2 API WS2_32.dll I have declared an extranl function as follows Function Integer getpeername( uint socket, Ref sockaddr addr,Ref integer addrlen ) Library "ws2_32.dll" and I then make a call to this external function from within a function I created named of_getpeername which accepts aui_socket as an argument, where aui_socket is the handle to the connected socket. as show below: Integer li_rtn, li_l...

HELP! Trying to Complie old Delphi program on any version of Delphi
Hey everyone I'm new to the programming world and unfortunately I have come across a big problem that I will hope I can get some help with. I have a program that was apparently created using delphi 3 and then finished using delphi 4 with some additional parts added later. I have found copies of amost every version of delphi ever made and installed them on my pc and attempted to compile this program in question. Unfortuantely I have yet to get it to compile without a few thousand error messages and I am st uck between a rock and a hard place. I know very little of Delphi programming, let a...

I can to execute one external (android/ios) program from one delphi program
For example I want to have one button, that execute or open one .apk file in android. I can to do this? how i can to do this? I can to do the same as iOS external program or .ipa file? ...

I can to install one not delphi program foir iOS into one iOS for delphi?
For example i have one programm builded as xcode for iOS, and i build one program as delphi for iOS. I want to have only one instalation, i can to add this xcode program into my delphi installer of my ios program? I can to do the same as android? how i can to to this? > {quote:title=oscar mejia wrote:}{quote} > For example i have one programm builded as xcode for iOS, and i build one program as delphi for iOS. I want to have only one instalation, i can to add this xcode program into my delphi installer of my ios program? > > I can to do the same as android? how i can to to...

Ping Robin Keir...ping....ping
Is SuperScan v4.0 compatible with Vista ??? TIA. -- "Not everything that counts can be counted, and not everything that can be counted counts." Johannes Niebach wrote: > Is SuperScan v4.0 compatible with Vista ??? > TIA. As long as you're pinging Robin... Hey Robin, is Neutron still okay? I haven't been able to reach my NTP servers lately from three different PCs. Got any ideas? Greg wrote: > Johannes Niebach wrote: >> Is SuperScan v4.0 compatible with Vista ??? >> TIA. > > As long as you're pinging Robin... &g...

winsock pb program
hi everyone: what's the best way to develop winsock pb program? winsock.pbl or MSWINSCK.OCX or ? http://www.topwizprogramming.com/freecode_winsock.html "lwl" <lwl@esunsoft.cn> wrote in message news:4a954fad@forums-1-dub... > hi everyone: > > what's the best way to develop winsock pb program? winsock.pbl or > MSWINSCK.OCX or ? > > > ...

winsock program with pb
hi everyone: what's the best way to develop winsock pb program? winsock.pbl or MSWINSCK.OCX or ? ...

Delphi and multicore programming
Hi all, does anybody test this : http://www.axon7.com/flx/products/jibu_for_delphi/ does it works well ? Best Regards > does anybody test this : > http://www.axon7.com/flx/products/jibu_for_delphi/ > does it works well ? Most probably yes, but do you have some particular reason to use such? It's usually much better to keep threads in your own hands instead of using 3rd party. ...

Delphi programming for WinCE?
Hi Recently obtained a PDA which was supposed to be the target of a delphi app i've been working on. WinCE doesn't like the .exe saying it isn't runnable. Is it possible to run delphi apps on CE? - I'm sure I asked this a few years back and was told yes but now i'm not so sure! Cheers Jamie Jamie Dale wrote: > Hi > > Recently obtained a PDA which was supposed to be the target of a > delphi app i've been working on. WinCE doesn't like the .exe saying > it isn't runnable. > > Is it possible to run delphi apps on CE...

web programming with delphi
Does anyone know how to get in touch with Andrew J. Wozniewicz, the author of "Web Programming with Delphi"? Does anyone have this book and if so, can you provide a recommendation. Was it helpful. I want to get a copy of it but it is out of print. So I guess it is near to impossible to find a copy. Is anyone willing to sell their used copy? Thanks. Randall H. Carpenter Hi Randall, > Does anyone know how to get in touch with Andrew J. Wozniewicz, the author > of "Web Programming with Delphi"? This book never existed. > Does anyone ha...

Web resources about - A ping program. - embarcadero.delphi.winsock

Program - Wikipedia, the free encyclopedia
Text is available under the Creative Commons Attribution-ShareAlike License ;additional terms may apply. By using this site, you agree to the ...

Verizon starts testing its new sponsored data program
Just as expected, Verizon has officially unveiled its new sponsored data program, FreeBee Data. With FreeBee Data, content providers and businesses ...

This Dutch e-Golf Lease Program Requires Car-Sharing
... of free electricity during the year. But there’s a catch. They have to let other people rent or [&hellip This Dutch e-Golf Lease Program Requires ...

Verizon Finally Catches Up To T-Mobile, AT&T; Launches Program To Free Up More Data For Mobile Subscribers ...
... . That day is apparently today, as the largest wireless provider in the U.S. launched FreeBee Data, its version of T-Mobile and AT&T’s programs ...

Loyalty program begs for iPads back after special offer gaffe
A New Zealand loyalty card program is appealing to its customers’ “good nature” to return brand new iPads after it mistakenly made them available ...

Rachel Nichols To Host Daily NBA Program On ESPN
ESPN has tapped returning reporter Rachel Nichols as host of a new, daily NBA-focused program. The Jump is slated to debut Thursday, February ...

Verizon Introduces FreeBee Data, a Sponsored Data Program…
... neutrality because, well, money. You already knew that, though. But let’s say for some reason, if you didn’t know that, maybe their new program ...

Does Verizon's FreeBee Sponsored Data Program Trash Net Neutrality?
... preference for content providers) and T-Mobile's self-described "foul mouthed" CEO, John Legere . At issue is whether T-Mo's Binge On program, ...

Mini Joins Automakers' Rush To Fund Startups With Urban-X Program
BMW's Mini brand now is joining the movement by automakers and many other huge companies to get closer to innovative and disruptive technologies, ...

Parents say middle school's anti-bullying program violated kids' privacy
Parents say middle school's anti-bullying program violated kids' privacy

Resources last updated: 1/20/2016 11:00:11 PM