uses Winsock
//
function PortTCPIsOpen(dwPort : Word; ipAddressStr:string) : boolean;
var
client : sockaddr_in;
sock : Integer;
begin
client.sin_family := AF_INET;
client.sin_port := htons(dwPort);
client.sin_addr.s_addr := inet_addr(PChar(ipAddressStr));
sock :=socket(AF_INET, SOCK_STREAM, 0);
Result:=connect(sock,client,SizeOf(client))=0;
end;
procedure Ports();
var
ret : Integer;
wsdata : WSAData;
begin
Form1.Memo1.Lines.Add('Init WinSock');
ret := WSAStartup($0002, wsdata);
if ret <> 0 then exit;
try
Form1.Memo1.Lines.Add('Description : '+wsData.szDescription);
Form1.Memo1.Lines.Add('Status : '+wsData.szSystemStatus);
if PortTCPIsOpen(80 , '192.168.0.1') then // Hier können Port und IP bestimmt werden.
Form1.Memo1.Lines.Add('Open')
else
Form1.Memo1.Lines.Add('Close');
finally
WSACleanup; //terminates use of the Winsock
end;
end;
Beispiel :
procedure TForm1.Button1Click(Sender: TObject);
begin
ports();
end;
Keine Kommentare:
Kommentar veröffentlichen