根据IP来ping就不慢了,这段代码是根据计算机名获得IP的,不过是pascal的,你可以自己转一下
function GetHostIP(HostName: String): String;
var
buf:pChar;
iWsaRet:Integer;
Data:WSAData;
hostent:PHostEnt;
begin
Result := '';
iWsaRet := WSAStartup($101,Data);
if iWsaRet<>0 then
begin
ShowMessage('Socket initialize error!');
Exit;
end;
buf := Allocmem(60);
strcopy(buf,PChar(HostName));
if Trim(buf)='' then
gethostname(buf,60);
hostent := gethostbyname(buf);
Freemem(buf,60);
if hostent=nil then
Exit;
Result := inet_ntoa(pinAddr(hostent^.h_addr^)^);
WSACleanup();
end;