I am using libssh to make my own ssh server (some kind of honeypot). I would like to save the ip address of connected client into my logfile. How to get this IP address? Programming in c++. Thanks in advance guys!
2 Answers
Here is little function I'm using.
string getClientIp(ssh_session session) { struct sockaddr_storage tmp; struct sockaddr_in *sock; unsigned int len = 100; char ip[100] = "\0"; getpeername(ssh_get_fd(session), (struct sockaddr*)&tmp, &len); sock = (struct sockaddr_in *)&tmp; inet_ntop(AF_INET, &sock->sin_addr, ip, len); string ip_str = ip; return ip_str; } It is based on function "get_client_ip" fromhttps://github.com/PeteMo/sshpot/blob/master/auth.c where is complete SSH honeypot implementation.