Solved

Questions about Ping

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

Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

Join & Write a Comment

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 Raise your hands if you were as upset with FireMonkey as I was when I discovered that there was no TListview.  I use TListView in almost all of my applications I've written, and I was not going to compromise by resorting to TStringGrid…
Illustrator's Shape Builder tool will let you combine shapes visually and interactively. This video shows the Mac version, but the tool works the same way in Windows. To follow along with this video, you can draw your own shapes or download the file…
This video gives you a great overview about bandwidth monitoring with SNMP and WMI with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're looking for how to monitor bandwidth using netflow or packet s…

747 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

11 Experts available now in Live!

Get 1:1 Help Now