Solved

Questions about Ping

Posted on 2002-07-16
5
172 Views
Last Modified: 2010-04-04
I have some question about ping.

If computer A ping computer B and uses B's computer name rather than Ip address, is there a way, like APIs, to convert computer name to ip address?

Computer A ping computer B with an echo string, how a program running on computer B receives the an echo string?

Thank u very much.


Peter Shaw
0
Comment
Question by:petershaw9
5 Comments
 
LVL 45

Expert Comment

by:aikimark
ID: 7156854
what you get back from your PING should include computer B's IP address.

There are some other services that do some of this DNS lookup for you.  I don't know of an API that does this, since this is a DNS function.

===========================
I don't understand your second question.
0
 
LVL 17

Expert Comment

by:geobul
ID: 7156948
Hi,
If both computers are in the same LAN:

uses Winsock;

function GetRemoteIPAddress(ComputerName : string) : string;
var
  wsdata : TWSAData;
  he : PHostEnt;
  ss : pchar;
  ip : TInAddr;
begin
  WSAStartup(MakeWord(1, 1), wsdata);
  he := gethostbyname(pchar(ComputerName));
  if he<>nil then begin
    ip.S_addr := integer(pointer(he^. h_addr_list^)^);
    ss := inet_ntoa(ip);
    Result := string(ss);
  end;
  WSACleanup();
end;

// usage:
procedure TForm1.Button1Click(Sender: TObject);
begin
  ShowMessage(GetRemoteIPAddress('ComputerB'));
end;

Regards, Geo
0
 

Expert Comment

by:ryan_sabarre
ID: 7159001
did you use the tsocketserver?
0
 

Author Comment

by:petershaw9
ID: 7159275
Thank u very much for the help. But I still wish you help me for my second question.

I was using delphi components like indy, TseverSocket, to send msg to other computer. But these components do not have timeout property. So if the remoter computer is not currently in the network, the program is hanging for long time. To solve the problem, I downlosad a demo that uses microsoft ICMP.dll. the api is following:
Function IcmpSendEcho;          external 'Icmp.Dll';

IcmpSendEcho (ICMPPort, IPAddress,
          EchoString, Length (EchoString), nil,
          @PingReply, SizeOf (PingReply), PingTimeout);

So, firstly, I need get the remote computer IP address by its computer name. This question has answered by Geo.

The second question is related to the IcmpSendEcho function. If my program on the remote computer can read the EchoString (passed as parameter in IcmpSendEcho ), then I don't need use indy or other components to send msg to the remote computer.

Thank u again for the help.

Peter
0
 
LVL 17

Accepted Solution

by:
geobul earned 300 total points
ID: 7159351
Hi Peter,

I'm afraid that you can't use ICMP for transfering data between computers. The reason is that the receiving computer (remote in your case) simply sends all the packets back to the originator. This is done in the IP layer internally and you can't change this behaviour as far as I know.

Regards, Geo
0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

The uses clause is one of those things that just tends to grow and grow. Most of the time this is in the main form, as it's from this form that all others are called. If you have a big application (including many forms), the uses clause in the in…
Creating an auto free TStringList The TStringList is a basic and frequently used object in Delphi. On many occasions, you may want to create a temporary list, process some items in the list and be done with the list. In such cases, you have to…
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…

828 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question