1、已知另一台机器的IP,如何判断本机是否和它连通?
2、以知两个机器(都非本机)的IP地址,如何判断这两台机器是否连通?谢谢!

解决方案 »

  1.   

    1.ping 另一台机得ip 
    2.ping两台机的的ip在本机上
      

  2.   

    delphi编程实现ping操作 
    首先,对编程中需要的动态链接库作一简要说明:在windows的system目录下,你可以找到icmp.dll文件,该动态链接库提供了icmp协议的所有功能,我们的编程就建立在对该动态链接库的调用上。 
      icmp.dll文件内的调用函数说明如下: 
      1、icmpcreatefile 
      打开一个句柄,通过该句柄你可以发送icmp的请求回送报文。 
      2、icmpclosehandle 
      关闭你通过icmpcreatefile函数打开的句柄。 
      3、icmpsendecho 
      通过你打开的句柄发送icmp请求,在超时或应答报文接收后返回。其参数基本上和它的帧结构一致,可参看下面的程序部分,其具体含意你可以参看有关icmp协议的书籍。 
      初步了解了上述的三个函数后,我们就可以开始编程了。 
      首先,我们的程序运行后应该有如图1所示的基本功能。为此,我们可先在delphi的窗口中放入右上图中所示的控件,如按钮、编辑框和文本显示框等。 
      (g72.jpg) 
      例程运行示意图 
      然后,在程序的开始部分(formcreate)对winsocket进行初始化,其作用是申明使用的版本信息,同时调入icmp.dll库。 
      type 
       pipoptioninformation = ^tipoptioninformation; 
       tipoptioninformation = packed record 
       ttl: byte; 
       tos: byte; 
       flags: byte; 
       optionssize: byte; 
       optionsdata: pchar; 
       end; 
       picmpechoreply = ^ticmpechoreply; 
       ticmpechoreply = packed record 
       address: dword; 
       status: dword; 
       rtt: dword; 
       datasize: word; 
       reserved: word; 
       data: pointer; 
       options: tipoptioninformation; 
       end; 
       ticmpcreatefile = function: thandle; stdcall; 
       ticmpclosehandle = function(icmphandle: thandle): boolean; stdcall; 
       ticmpsendecho = function(icmphandle:thandle; 
       destinationaddress: dword; 
       requestdata: pointer; 
       requestsize: word; 
       requestoptions: pipoptioninformation; 
       replybuffer: pointer; 
       replysize: dword; 
       timeout: dword 
       ): dword; stdcall; 
       tmyping = class(tform) 
       panel1: tpanel; 
       label1: tlabel; 
       pingedit: tedit; 
       exebtn: tbutton; 
       button2: tbutton; 
       button3: tbutton; 
       statusshow: tmemo; 
       procedure button3click(sender: tobject); 
       procedure formcreate(sender: tobject); 
       procedure exebtnclick(sender: tobject); 
       private 
       { private declarations } 
       hicmp: thandle; 
       icmpcreatefile : ticmpcreatefile; 
       icmpclosehandle: ticmpclosehandle; 
       icmpsendecho: ticmpsendecho; 
       public 
       { public declarations } 
      end; 
      procedure tmyping.formcreate(sender: tobject); 
      var 
       wsadata: twsadata; 
       hicmpdll: hmodule; 
      begin 
       wsastartup($101, wsadata); 
       // load the icmp.dll stuff 
       hicmpdll := loadlibrary('icmp.dll'); 
       @icmpcreatefile := getprocaddress(hicmpdll, 'icmpcreatefile'); 
       @icmpclosehandle := getprocaddress(hicmpdll, 'icmpclosehandle'); 
       @icmpsendecho := getprocaddress(hicmpdll, 'icmpsendecho'); 
       hicmp := icmpcreatefile; 
       statusshow.text := ''; 
       statusshow.lines.add('目的ip地址 字节数 返回时间(毫秒)'); 
      end; 
      接下来,就要进行如下所示的ping操作的实际编程过程了。 
      procedure tmyping.exebtnclick(sender: tobject); 
      var 
       ipopt:tipoptioninformation;// ip options for packet to send 
       fipaddress:dword; 
       preqdata,prevdata:pchar; 
       pipe:picmpechoreply;// icmp echo reply buffer 
       fsize: dword; 
       mystring:string; 
       ftimeout:dword; 
       buffersize:dword; 
      begin 
       if pingedit.text < > '' then 
       begin 
       fipaddress := inet_addr(pchar(pingedit.text)); 
       fsize := 40; 
       buffersize := sizeof(ticmpechoreply) + fsize; 
       getmem(prevdata,fsize); 
       getmem(pipe,buffersize); 
       fillchar(pipe^, sizeof(pipe^), 0); 
       pipe^.data := prevdata; 
       mystring := 'hello,world'; 
       preqdata := pchar(mystring); 
       fillchar(ipopt, sizeof(ipopt), 0); 
       ipopt.ttl := 64; 
       ftimeout := 4000; 
       icmpsendecho(hicmp, fipaddress, preqdata, length(mystring), @ipopt, pipe, buffersize, ftimeout); 
       if preqdata^ = pipe^.options.optionsdata^ then 
       begin 
       statusshow.lines.add(pchar(pingedit.text) + ' ' +inttostr(pipe^.datasize) + ' ' +inttostr(pipe^.rtt)); 
       end; 
       freemem(prevdata); 
       freemem(pipe); 
       end 
      end; 
      通过上面的编程,我们就实现了ping功能的界面操作。实际上,icmp协议的功能还有很多,都可以通过对icmp.dll的函数调用来实现
      

  3.   

    这不是办法.因为你要考虑到另一台机上可能装得有防火墙,ping只会返回超时的.
      

  4.   

    不晓得怎么回事,一运行就抱错。
    还是 运行到wsastartup($101, wsadata);就抱错了。
      

  5.   

    Uses winsock;
    在Uses段中加上WINSOCK试试