Sign in Join

Live chat for Free Pascal, Lazarus, Delphi and every Pascal programmer.

Mailing lists / lazarus / 2016-11

fpConnect

3 messages · 2 people ·

Reply by email Subscribe to this list Your subscription

Read-only archive. Use j and k to move between messages.

Kaj Mikkelsen

Hi

I need a method to tell whether a specific port is open on a remote host.

Ihave written a function for it, but it seems that fpConnect always returns 0.

What am I missing?

/Kaj

Function TMainForm.OpenPort(  IP:String;Port:Integer): Boolean;
Var
   Sock: LongInt;
   IPAddr: sockaddr;
begin
   sock := fpsocket(AF_INET, SOCK_DGRAM, 0);
   IPAddr.sin_family := AF_INET;
   IPAddr.sin_addr.s_addr := StrToHostAddr(IP).s_addr;
   IPAddr.sin_port := htons(port);
   if (fpConnect(sock, at IPAddr,SizeOf(IPAddr)) = 0) then
   Begin
     Result :=  True;
     CloseSocket(sock);
   End
   Else
   Begin
     Result := False;
   end;
end;

Reply by email

Kaj Mikkelsen
to Mattias Gaertner

Forgot to mention that I run Lazarus on Linux mint 17.3

By open I mean, that the host is ready to accept connections. Like if you run nmap -p 22 xxx.xxx.xxx.xxx to se if the host is accepting SSH connections.

/Kaj

Mattias Gaertner wrote 9 lines
On Tue, 15 Nov 2016 16:37:32 +0100 Kaj Mikkelsen via Lazarus wrote: > Hi > > I need a method to tell whether a specific port is open on a remote host. Please define "open". Mattias

Reply by email