Unix Technical Forum

howto get telnet client ip

This is a discussion on howto get telnet client ip within the Slackware Linux Support forums, part of the Unix Operating Systems category; --> Hello all, How can i retrieve the ip-address of a telnet client. If a client ssh's, you can check ...


Go Back   Unix Technical Forum > Unix Operating Systems > Slackware Linux Support

FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 02-20-2008, 02:12 PM
lana.minrod@bankarea.com
 
Posts: n/a
Default howto get telnet client ip

Hello all,

How can i retrieve the ip-address of a telnet client.

If a client ssh's, you can check the SSH_CLIENT enviremont variable, but i
can see no such variable when it's a telnet session.

I can however see the ip-adress with 'who -a', but i don't know how to
substract the correct information from this result, as several clients log
in with the same username.


Best regards,
lana.minrod@balcanicsoft.com
webmaster@bankarea.com
http://www.bankarea.com
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #2 (permalink)  
Old 02-20-2008, 02:12 PM
Chris Sorenson
 
Posts: n/a
Default Re: howto get telnet client ip


lana.minrod@bankarea.com wrote:
> Hello all,
>
> How can i retrieve the ip-address of a telnet client.
>
> If a client ssh's, you can check the SSH_CLIENT enviremont variable, but i
> can see no such variable when it's a telnet session.
>
> I can however see the ip-adress with 'who -a', but i don't know how to
> substract the correct information from this result, as several clients log
> in with the same username.
>


How about:

netstat --inet --numeric-hosts

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #3 (permalink)  
Old 02-20-2008, 02:12 PM
Jeremiah DeWitt Weiner
 
Posts: n/a
Default Re: howto get telnet client ip

lana.minrod@bankarea.com wrote:
> I can however see the ip-adress with 'who -a', but i don't know how to
> substract the correct information from this result, as several clients log
> in with the same username.


1. Don't use telnet.
2. Don't let several clients use the same username.

That aside, your best bet is to get the tty of the session and grep
that out of the output of 'w' or 'who' or whatever, like so:

sadalsuud:~$ TTY=`tty` ; who -a | grep ${TTY#/dev/}
jdw + pts/0 Jan 25 10:20 . 5048 (207.218.71.5)


--
Oh to have a lodge in some vast wilderness. Where rumors of oppression
and deceit, of unsuccessful and successful wars may never reach me
anymore.
-- William Cowper
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #4 (permalink)  
Old 02-20-2008, 02:12 PM
Henrik Carlqvist
 
Posts: n/a
Default Re: howto get telnet client ip

lana.minrod@bankarea.com wrote:
> How can i retrieve the ip-address of a telnet client.


gcc -ansi -pedantic -Wall -o rhost3 rhost.c

rhost.c:
-8<------------------------------------------------
#include <stdio.h>
#include <utmp.h>
#include <unistd.h>
#include <string.h>
#include <sys/types.h>

char *rhost();

int main(int argc, char **argv)
{
char szText[UT_HOSTSIZE];
int iLen;

strncpy(szText, rhost(), UT_HOSTSIZE-1);
iLen=strlen(szText);
if(iLen == (UT_HOSTSIZE-1))
while(iLen--)
if(szText[iLen]=='.')
{
szText[iLen]='\0';
iLen=0;
}
printf("%s\n", szText);
return 0;
}

char *rhost()
{
struct utmp *suIn;
pid_t tpId;

tpId=getppid();
setutent();
while((suIn=getutent()))
if(suIn->ut_pid==tpId)
{
endutent();
if(strcmp(suIn->ut_host, ":0.0"))
return suIn->ut_host;
else
return ("");
}
endutent();
return("Unknown host!");
}
-8<------------------------------------------------

regards Henrik
--
The address in the header is only to prevent spam. My real address is:
hc7(at)uthyres.com Examples of addresses which go to spammers:
root@variousus.net root@localhost

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On
Forum Jump


All times are GMT. The time now is 09:05 AM.


Powered by vBulletin® Version 3.6.5
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.2.0
www.UnixAdminTalk.com