Registriert seit: 25. Jun 2003
Ort: Thüringen
2.950 Beiträge
|
Re: Ping per WinAPI
31. Aug 2003, 18:14
Delphi-Quellcode:
function PortPresent( const URL: String; Port: DWord = 80): Boolean;
// URL can be like [url]www.enterwickler.com[/url] or an IP like 127.0.0.1
var
S: TSocket;
A: SOCKADDR_IN;
W: TWsaData;
H: pHostEnt;
begin
Result := False;
if WsaStartup(MakeWord(1, 1), W) = 0 then
begin
H := GetHostByName(PChar( URL));
if H <> nil then
begin
FillChar(A, SizeOf(A), 0);
A.sin_family := AF_INET;
A.sin_addr.S_addr := PDWord(H.h_addr_list^)^;
A.sin_port := htons(Port);
S := Socket(AF_INET, SOCK_STREAM, 0);
if S <> INVALID_SOCKET then
begin
Result := Connect(S, A, SizeOf(A)) = 0;
CloseSocket(S);
end;
end;
end;
WSACleanup;
end;
|
|
Zitat
|