Solved

Questions about Ping

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

Netscaler Common Configuration How To guides

If you use NetScaler you will want to see these guides. The NetScaler How To Guides show administrators how to get NetScaler up and configured by providing instructions for common scenarios and some not so common ones.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Path  to current project in Delphi. 2 79
Working this component WebCopy with proxy, help 3 84
Convert GUI app into console app for Win32 Env 5 100
select query - oracle 16 100
Hello everybody This Article will show you how to validate number with TEdit control, What's the TEdit control? TEdit is a standard Windows edit control on a form, it allows to user to write, read and copy/paste single line of text. Usua…
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…
Along with being a a promotional video for my three-day Annielytics Dashboard Seminor, this Micro Tutorial is an intro to Google Analytics API data.
Microsoft Active Directory, the widely used IT infrastructure, is known for its high risk of credential theft. The best way to test your Active Directory’s vulnerabilities to pass-the-ticket, pass-the-hash, privilege escalation, and malware attacks …

773 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