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 ...
| |||||||
| FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
| ||||
| 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 |
| |||
| 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 |
| |||
| 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 |
| ||||
| 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 |
| Thread Tools | |
| Display Modes | |
|
|