Solved

Questions about Ping

Posted on 2002-07-16
5
168 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Have you ever had your Delphi form/application just hanging while waiting for data to load? This is the article to read if you want to learn some things about adding threads for data loading in the background. First, I'll setup a general applica…
Introduction I have seen many questions in this Delphi topic area where queries in threads are needed or suggested. I know bumped into a similar need. This article will address some of the concepts when dealing with a multithreaded delphi database…
Internet Business Fax to Email Made Easy - With eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…
Video by: Mark
This lesson goes over how to construct ordered and unordered lists and how to create hyperlinks.

895 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

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now