delphi 怎麼ping電腦名稱或ip 地址 Delphi / Windows SDK/API
http://www.delphi2007.net/DelphiNetwork/html/delphi_20061201140126219.html
delphi 怎麼ping電腦名稱或ip 地址???
indy idICMP
function TMainForm.ping( var url: string):boolean; var
aIdICMPClient: TIdICMPClient;
begin
aIdICMPClient:= TIdICMPClient.Create(nil);
aIdIcmpclient.ReceiveTimeout:=500;
aIdICMPClient.Host:= url;
try
aIdICMPClient.Ping();
except
Result:= False;
end;
if (aidicmpclient.ReplyStatus.fromipaddress<>'0.0.0.0')
and (aidicmpclient.ReplyStatus.fromipaddress<>'') then
result:=true
else
result:=false;
aIdICMPClient.Free;
end;
我這裡能ping 通ip地址,但是ping 不通電腦名稱?
為何
在“CMD”裡面Ping一下看
另外,如果作業系統是XP,有時是Ping機器名時是Ping不到的
在HOSTs檔案裡面加一條就可以了:(XP: C:\WINDOWS\system32\drivers\etc目錄下)
# Copyright (c) 1993-1999 Microsoft Corp.
#
# This is a sample HOSTS file used by Microsoft TCP/IP for Windows.
#
# This file contains the mappings of IP addresses to host names. Each
# entry should be kept on an individual line. The IP address should
# be placed in the first column followed by the corresponding host name.
# The IP address and the host name should be separated by at least one
# space.
#
# Additionally, comments (such as these) may be inserted on individual
# lines or following the machine name denoted by a '#' symbol.
#
# For example:
#
# 102.54.94.97 rhino.acme.com # source server
# 38.25.63.10 x.acme.com # x client host
127.0.0.1 localhost
#把你的IP和HOST按下面格式輸入
200.211.110.133 SANMAOTUO
如果加上樓上說的.肯定是可以通的.
但是區域網路內醜那麼多電腦.我不可能沒一台都去改一下hosts檔案吧
.好像是dns的問題.
我本來想用api把名字解悉為ip,但是如果不在hosts裡面加的話。解析不出來。
有沒有別的辦法啊。。
高手們,幫幫我把
路過