1

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 2

2

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.

Sign up to request clarification or add additional context in comments.

Comments

-1
s = ssh_get_fd(session); getpeername(s, ...); 

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.