如何测试局域网中的机器通不通 网中有一台202.32.56.112。我想测一下跟它通不通。怎么能做到。最好说明原理和实现方法。分不够。再加+++在线等。。 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 ping -t 202.32.56.112-t 加后面 Linux 下就不行了 ping命令--详细帮助 校验与远程计算机或本地计算机的连接。只有在安装 TCP/IP 协议之后才能使用该命令。ping [-t] [-a] [-n count] [-l length] [-f] [-i ttl] [-v tos] [-r count] [-s count] [[-j computer-list] | [-k computer-list]] [-w timeout] destination-list 参数 -t 校验与指定计算机的连接,直到用户中断。 -a 将地址解析为计算机名。 -n count 发送由 count 指定数量的 ECHO 报文,默认值为 4。 -l length 发送包含由 length 指定数据长度的 ECHO 报文。默认值为 64 字节,最大值为 8192 字节。 -f 在包中发送“不分段”标志。该包将不被路由上的网关分段。 -i ttl 将“生存时间”字段设置为 ttl 指定的数值。 -v tos 将“服务类型”字段设置为 tos 指定的数值。 -r count 在“记录路由”字段中记录发出报文和返回报文的路由。指定的 Count 值最小可以是 1,最大可以是 9 。 -s count 指定由 count 指定的转发次数的时间邮票。 -j computer-list 经过由 computer-list 指定的计算机列表的路由报文。中间网关可能分隔连续的计算机(松散的源路由)。允许的最大 IP 地址数目是 9 。 -k computer-list 经过由 computer-list 指定的计算机列表的路由报文。中间网关可能分隔连续的计算机(严格源路由)。允许的最大 IP 地址数目是 9 。 -w timeout 以毫秒为单位指定超时间隔。 destination-list 指定要校验连接的远程计算机。 关于 Ping 的详细信息 Ping--注意 Ping 命令通过向计算机发送 ICMP 回应报文并且监听回应报文的返回,以校验与远程计算机或本地计算机的连接。对于每个发送报文, Ping 最多等待 1 秒,并打印发送和接收把报文的数量。比较每个接收报文和发送报文,以校验其有效性。默认情况下,发送四个回应报文,每个报文包含 64 字节的数据(周期性的大写字母序列)。可以使用 Ping 实用程序测试计算机名和 IP 地址。如果能够成功校验 IP 地址却不能成功校验计算机名,则说明名称解析存在问题。这种情况下,要保证在本地 HOSTS 文件中或 DNS 数据库中存在要查询的计算机名。下面显示 Ping 输出的示例:(Windows用户可用:开始->运行,输入"command" 调出command窗口使用此命令)C:\>ping ds.internic.netPinging ds.internic.net [192.20.239.132] with 32 bytes of data:Reply from 192.20.239.132: bytes=32 time=101ms TTL=243Reply from 192.20.239.132: bytes=32 time=100ms TTL=243Reply from 192.20.239.132: bytes=32 time=120ms TTL=243Reply from 192.20.239.132: bytes=32 time=120ms TTL=243 同上意见,PING在UNIX或是LINUX环境下必须带次数,否则它会一直干下去,不会停止。 http://www.delphipages.com/news/detaildocs.cfm?ID=93unit Ping;interfaceuses Windows, SysUtils, Classes;type TSunB = packed record s_b1, s_b2, s_b3, s_b4: byte; end; TSunW = packed record s_w1, s_w2: word; end; PIPAddr = ^TIPAddr; TIPAddr = record case integer of 0: (S_un_b: TSunB); 1: (S_un_w: TSunW); 2: (S_addr: longword); end; IPAddr = TIPAddr;function IcmpCreateFile : THandle; stdcall; external 'icmp.dll';function IcmpCloseHandle (icmpHandle : THandle) : boolean; stdcall; external 'icmp.dll'function IcmpSendEcho (IcmpHandle : THandle; DestinationAddress : IPAddr; RequestData : Pointer; RequestSize : Smallint; RequestOptions : pointer; ReplyBuffer : Pointer; ReplySize : DWORD; Timeout : DWORD) : DWORD; stdcall; external 'icmp.dll';function Ping(InetAddress : string) : boolean;implementationuses WinSock;function Fetch(var AInput: string; const ADelim: string = ' '; const ADelete: Boolean = true) : string;var iPos: Integer;begin if ADelim = #0 then begin // AnsiPos does not work with #0 iPos := Pos(ADelim, AInput); end else begin iPos := Pos(ADelim, AInput); end; if iPos = 0 then begin Result := AInput; if ADelete then begin AInput := ''; end; end else begin result := Copy(AInput, 1, iPos - 1); if ADelete then begin Delete(AInput, 1, iPos + Length(ADelim) - 1); end; end;end;procedure TranslateStringToTInAddr(AIP: string; var AInAddr);var phe: PHostEnt; pac: PChar; GInitData: TWSAData;begin WSAStartup($101, GInitData); try phe := GetHostByName(PChar(AIP)); if Assigned(phe) then begin pac := phe^.h_addr_list^; if Assigned(pac) then begin with TIPAddr(AInAddr).S_un_b do begin s_b1 := Byte(pac[0]); s_b2 := Byte(pac[1]); s_b3 := Byte(pac[2]); s_b4 := Byte(pac[3]); end; end else begin raise Exception.Create('Error getting IP from HostName'); end; end else begin raise Exception.Create('Error getting HostName'); end; except FillChar(AInAddr, SizeOf(AInAddr), #0); end; WSACleanup;end;function Ping(InetAddress : string) : boolean;var Handle : THandle; InAddr : IPAddr; DW : DWORD; rep : array[1..128] of byte;begin result := false; Handle := IcmpCreateFile; if Handle = INVALID_HANDLE_VALUE then Exit; TranslateStringToTInAddr(InetAddress, InAddr); DW := IcmpSendEcho(Handle, InAddr, nil, 0, nil, @rep, 128, 0); Result := (DW <> 0); IcmpCloseHandle(Handle);end;end. 是编程实现。不是用PING。大家帮忙。 可以使用delphi7的idicmpclient组件,楼主去好好研究! 我有一个 源程序买书时 带来的 PING 的 一个 Edit1 一个Button1 一个 StringGrid1 以下代码unit ping;interfaceuses Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs, Grids, winsock, StdCtrls;type PIPOptionInformation = ^TIPOptionInformation; TIPOptionInformation = packed record TTL: Byte; TOS: Byte; Flags: Byte; OptionsSize: Byte; OptionsData: PChar; end; type 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;type TForm1 = class(TForm) StringGrid1: TStringGrid; Edit1: TEdit; Button1: TButton; Label1: TLabel; procedure FormCreate(Sender: TObject); procedure Button1Click(Sender: TObject); procedure FormDestroy(Sender: TObject); private { Private declarations } hICMP: THANDLE; IcmpCreateFile : TIcmpCreateFile; IcmpCloseHandle:TIcmpCloseHandle; IcmpSendEcho: TIcmpSendEcho; line:integer; public { Public declarations } hICMPdll: HMODULE; end;var Form1: TForm1;implementation{$R *.DFM}procedure TForm1.FormCreate(Sender: TObject);begin hICMPdll := LoadLibrary('icmp.dll'); @ICMPCreateFile:= GetProcAddress(hICMPdll, 'IcmpCreateFile'); @IcmpCloseHandle := GetProcAddress(hICMPdll, 'IcmpCloseHandle'); @IcmpSendEcho := GetProcAddress(hICMPdll, 'IcmpSendEcho'); hICMP := IcmpCreateFile; StringGrid1.Cells[0,0]:=' '; StringGrid1.Cells[1,0]:='返回地址'; StringGrid1.cells[2,0]:='返回数据包大小'; StringGrid1.Cells[3,0]:='RTT(Round-Trip-Time)'; line:=1;end;procedure TForm1.Button1Click(Sender: TObject);var IPOpt:TIPOptionInformation; FIPAddress:DWORD; pReqData,pRevData:PChar; pIPE:PIcmpEchoReply; FSize: DWORD; MyString:string; FTimeOut:DWORD; BufferSize:DWORD;begin if Edit1.Text <> '' then begin FIPAddress:=inet_addr(PChar(Edit1.Text)); if Fipaddress=INADDR_NONE then Messagebox(self.handle,'地址无效','Ping32',64) else begin FSize:=80; BufferSize:=SizeOf(TICMPEchoReply)+FSize; GetMem(pRevData,FSize); GetMem(pIPE,BufferSize); FillChar(pIPE^, SizeOf(pIPE^), 0); pIPE^.Data := pRevData; MyString := 'Argen Ping32 Sending Message.'; pReqData := PChar(MyString); FillChar(IPOpt, Sizeof(IPOpt), 0); IPOpt.TTL:= 64; FTimeOut :=500; IcmpSendEcho(hICMP, FIPAddress, pReqData, Length(MyString),@IPOpt, pIPE, BufferSize, FTimeOut); try try if pReqData^ = pIPE^.Options.OptionsData^ then with StringGrid1 do begin if line>1 then rowcount:=line+1; cells[0,line]:=inttoStr(line); cells[1,line]:=Edit1.Text; cells[2,line]:=inttoStr(pIPE^.DataSize); cells[3,line]:=IntToStr(pIPE^.RTT); row:=rowcount-1; line:=line+1; end; except Messagebox(self.handle,'目标不可到','Ping32',64) end; finally FreeMem(pRevData); FreeMem(pIPE); end; end; end;end;procedure TForm1.FormDestroy(Sender: TObject);begin icmpclosehandle(hicmp); freelibrary(hicmpdll);end;end. 多个edit,可以用循环语句简化一下吗? 希望火箭抢七战干掉湖人 Delphi 2005真实展现 怎么才能把从数据库中取出的数据放入listview中显示呢? 大家都来看看吧:如何将程序中 生成的子窗口 用一个 工具条来管理,就像Windows中的任务栏一样? 来大家算个基础题算法 求救!Microsoft Exchange,如何编程实现WEB受理自动开户? 能不能在工程文件中定义变量?? 如何将电视卡某个频道的节目录下来 怎样学习OO的思想? 急死了,急需一个身份证式的套打(DELPHI6) 添加数据时的一个问题
校验与远程计算机或本地计算机的连接。只有在安装 TCP/IP 协议之后才能使用该命令。ping [-t] [-a] [-n count] [-l length] [-f] [-i ttl] [-v tos] [-r count] [-s count] [[-j computer-list] | [-k computer-list]] [-w timeout] destination-list 参数 -t 校验与指定计算机的连接,直到用户中断。 -a 将地址解析为计算机名。 -n count 发送由 count 指定数量的 ECHO 报文,默认值为 4。 -l length 发送包含由 length 指定数据长度的 ECHO 报文。默认值为 64 字节,最大值为 8192 字节。 -f 在包中发送“不分段”标志。该包将不被路由上的网关分段。 -i ttl 将“生存时间”字段设置为 ttl 指定的数值。 -v tos 将“服务类型”字段设置为 tos 指定的数值。 -r count 在“记录路由”字段中记录发出报文和返回报文的路由。指定的 Count 值最小可以是 1,最大可以是 9 。 -s count 指定由 count 指定的转发次数的时间邮票。 -j computer-list 经过由 computer-list 指定的计算机列表的路由报文。中间网关可能分隔连续的计算机(松散的源路由)。允许的最大 IP 地址数目是 9 。 -k computer-list 经过由 computer-list 指定的计算机列表的路由报文。中间网关可能分隔连续的计算机(严格源路由)。允许的最大 IP 地址数目是 9 。 -w timeout 以毫秒为单位指定超时间隔。 destination-list 指定要校验连接的远程计算机。 关于 Ping 的详细信息 Ping--注意 Ping 命令通过向计算机发送 ICMP 回应报文并且监听回应报文的返回,以校验与远程计算机或本地计算机的连接。对于每个发送报文, Ping 最多等待 1 秒,并打印发送和接收把报文的数量。比较每个接收报文和发送报文,以校验其有效性。默认情况下,发送四个回应报文,每个报文包含 64 字节的数据(周期性的大写字母序列)。可以使用 Ping 实用程序测试计算机名和 IP 地址。如果能够成功校验 IP 地址却不能成功校验计算机名,则说明名称解析存在问题。这种情况下,要保证在本地 HOSTS 文件中或 DNS 数据库中存在要查询的计算机名。下面显示 Ping 输出的示例:(Windows用户可用:开始->运行,输入"command" 调出command窗口使用此命令)C:\>ping ds.internic.netPinging ds.internic.net [192.20.239.132] with 32 bytes of data:Reply from 192.20.239.132: bytes=32 time=101ms TTL=243Reply from 192.20.239.132: bytes=32 time=100ms TTL=243Reply from 192.20.239.132: bytes=32 time=120ms TTL=243Reply from 192.20.239.132: bytes=32 time=120ms TTL=243
一个 Edit1 一个Button1 一个 StringGrid1 以下代码
unit ping;interfaceuses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
Grids, winsock, StdCtrls;type
PIPOptionInformation = ^TIPOptionInformation;
TIPOptionInformation = packed record
TTL: Byte;
TOS: Byte;
Flags: Byte;
OptionsSize: Byte;
OptionsData: PChar;
end;
type 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;type
TForm1 = class(TForm)
StringGrid1: TStringGrid;
Edit1: TEdit;
Button1: TButton;
Label1: TLabel;
procedure FormCreate(Sender: TObject);
procedure Button1Click(Sender: TObject);
procedure FormDestroy(Sender: TObject);
private
{ Private declarations }
hICMP: THANDLE;
IcmpCreateFile : TIcmpCreateFile;
IcmpCloseHandle:TIcmpCloseHandle;
IcmpSendEcho: TIcmpSendEcho;
line:integer; public
{ Public declarations }
hICMPdll: HMODULE;
end;var
Form1: TForm1;
implementation{$R *.DFM}procedure TForm1.FormCreate(Sender: TObject);
begin
hICMPdll := LoadLibrary('icmp.dll');
@ICMPCreateFile:= GetProcAddress(hICMPdll, 'IcmpCreateFile');
@IcmpCloseHandle := GetProcAddress(hICMPdll, 'IcmpCloseHandle');
@IcmpSendEcho := GetProcAddress(hICMPdll, 'IcmpSendEcho');
hICMP := IcmpCreateFile;
StringGrid1.Cells[0,0]:=' ';
StringGrid1.Cells[1,0]:='返回地址';
StringGrid1.cells[2,0]:='返回数据包大小';
StringGrid1.Cells[3,0]:='RTT(Round-Trip-Time)';
line:=1;
end;procedure TForm1.Button1Click(Sender: TObject);
var
IPOpt:TIPOptionInformation;
FIPAddress:DWORD;
pReqData,pRevData:PChar;
pIPE:PIcmpEchoReply;
FSize: DWORD;
MyString:string;
FTimeOut:DWORD;
BufferSize:DWORD;
begin
if Edit1.Text <> '' then
begin
FIPAddress:=inet_addr(PChar(Edit1.Text));
if Fipaddress=INADDR_NONE then
Messagebox(self.handle,'地址无效','Ping32',64)
else
begin
FSize:=80;
BufferSize:=SizeOf(TICMPEchoReply)+FSize;
GetMem(pRevData,FSize);
GetMem(pIPE,BufferSize);
FillChar(pIPE^, SizeOf(pIPE^), 0);
pIPE^.Data := pRevData;
MyString := 'Argen Ping32 Sending Message.';
pReqData := PChar(MyString);
FillChar(IPOpt, Sizeof(IPOpt), 0);
IPOpt.TTL:= 64;
FTimeOut :=500;
IcmpSendEcho(hICMP, FIPAddress, pReqData, Length(MyString),@IPOpt, pIPE,
BufferSize, FTimeOut);
try
try
if pReqData^ = pIPE^.Options.OptionsData^ then
with StringGrid1 do
begin
if line>1 then rowcount:=line+1;
cells[0,line]:=inttoStr(line);
cells[1,line]:=Edit1.Text;
cells[2,line]:=inttoStr(pIPE^.DataSize);
cells[3,line]:=IntToStr(pIPE^.RTT);
row:=rowcount-1;
line:=line+1;
end;
except
Messagebox(self.handle,'目标不可到','Ping32',64)
end;
finally
FreeMem(pRevData);
FreeMem(pIPE);
end;
end;
end;
end;procedure TForm1.FormDestroy(Sender: TObject);
begin
icmpclosehandle(hicmp);
freelibrary(hicmpdll);
end;end.