Using the SimpleSSHServer demo, I learned how to get some of the info using IPEndpoint from WinSock on a TClientInfo object. (Similar code can also be found elsewhere in this forum.) Here's a simple function that returns a formatted address/port pair :10.0.0.1:1234 --> 10.0.0.2:22
Code: Select all
function GetScSSHClientAddrPort(ClientInfo: TScSSHClientInfo): string;
var
Sock: TIPEndPoint;
begin
Sock := nil;
try
Sock := TIPEndPoint.Create(PSockAddrIn(ClientInfo.SockAddr));
result := Sock.ToString+':'+IntToStr(Sock.Port);
finally
Sock.Free;
end;
end;
Feeding ClientInfo from the AfterClientConnect event to the above routine gives me the IP adddress & port of the client. I can cheat and say I already know my own port#, since I'm only listening on one port. What I need to know is how to determine the IP address of my own interface that the client connected to.
TScSSHClient - ????:1234 --> 10.0.0.2:22
After connecting, if I feed the SSHClient's .ClientInfo property to the same function, I get the address of the server that I connected to (handy, since I could've specified a name and thus not known the address) and my own port# used to establish the connection. As before, I do already know the port# that I'm connecting to. The missing piece of info is again my own IP address
How can I determine my own IP address being used for the connections? (Sorry, the Winsock API and I don't know each other well.)