How to ping the computer name or IP address in Delphi? Delphi/Windows SDK/API
Http://www.delphi2007.net/DelphiNetwork/html/delphi_20061201140126219.html
How does delphi ping the computer name or IP address ???
Indy idicmp
Function tmainform. Ping (var url: string): Boolean; var
Aidicmpclient: tidicmpclient;
Begin
Aidicmpclient: = tidicmpclient. Create (NiL );
Aidicmpclient. receivetimeout: = 500;
Aidicmpclient. HOST: = URL;
Try
Aidicmpclient. Ping ();
Except
Result: = false;
End;
If (aidicmpclient. replystatus. fromipaddress <> '0. 0.0.0 ')
And (aidicmpclient. replystatus. fromipaddress <> '') then
Result: = true
Else
Result: = false;
Aidicmpclient. Free;
End;
Can I ping the IP address but cannot ping the computer name?
Why
Ping in "cmd" to see
In addition, if the operating system is XP, sometimes the machine name cannot be pinged.
Add one in the hosts file: (XP: c: \ windows \ system32 \ drivers \ etc directory)
# Copyright (c) 1993-1999 Microsoft Corp.
#
# This is a sample hosts file used by Microsoft TCP/IP for Windows.
#
# This file contains the Mappings of IP addresses to host names. Each
# Entry shoshould be kept on an individual line. The IP address shold
# Be placed in the first column followed by the corresponding host name.
# The IP address and the host name shocould be separated by at least one
# Space.
#
# Additionally, comments (such as these) may be inserted on individual
# Lines or following the machine name denoted by a' # 'symbol.
#
# For example:
#
#102.54.94.97 rhino.acme.com # source server
#38.25.63.10 x.acme.com # X client host
127.0.0.1 localhost
# Input your IP address and host in the following format
200.211.110.20.sanmaotuo
If I add what I said upstairs, it will certainly work.
But there are so many ugly computers in the LAN. I can't change all my hosts files.
It seems to be a DNS problem.
I originally wanted to use the API to interpret the name as IP, but if it is not included in hosts. It cannot be parsed.
Is there any other way ..
Experts, please help me
Pass