Advertisement
Gov_777

Проверка доступности хоста от Àdam Blestsov

Oct 25th, 2016
293
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Delphi 0.50 KB | None | 0 0
  1. function CheckURLConnection(Host: String; Port: integer=80; Timeout: integer=1000): boolean;
  2. var TCP: TIdTCPClient;
  3. begin
  4. TCP:=TIdTCPClient.Create(nil);
  5. try
  6. TCP.Host:=Host;
  7. TCP.Port:=Port;
  8. TCP.ConnectTimeout:=Timeout;
  9. try
  10. TCP.Connect;
  11. Result:=TCP.Connected;
  12. except
  13. Result:=false;
  14. end;
  15. finally
  16. FreeAndNil(TCP);
  17. end;
  18. end;
  19.  
  20. procedure Tmain.test1Click(Sender: TObject);
  21. begin
  22. if CheckURLConnection('google.ru') then
  23. ShowMessage('Доступен')
  24. else
  25. ShowMessage('Недоступен');
  26. end;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement