Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Questions about Ping

Posted on 2002-07-16
5
Medium Priority
?
179 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 46

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 1200 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

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

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

Objective: - This article will help user in how to convert their numeric value become words. How to use 1. You can copy this code in your Unit as function 2. than you can perform your function by type this code The Code   (CODE) The Im…
In my programming career I have only very rarely run into situations where operator overloading would be of any use in my work.  Normally those situations involved math with either overly large numbers (hundreds of thousands of digits or accuracy re…
this video summaries big data hadoop online training demo (http://onlineitguru.com/big-data-hadoop-online-training-placement.html) , and covers basics in big data hadoop .
Loops Section Overview
Suggested Courses

916 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