If you are using *nix, robobunny's solution looks easy enough and you can use perl instead of the pipeline to process the output of 'who'.
OTOH, if you want a slightly more perlish solution, you can use Sys::Utmp to look up the login record. You can find out what the login device is with the shell's tty command.
If you want to support *nix, Win*, etc, I'd possibly put a shim on port 23 (telnet) so it logged the connection somewhere before starting the real telnet daemon. Win32 may have an environment variable you could use instead, but that probably depends on what telnet server you are using. I suggest CLIENTNAME is a place to start.
HTH, --traveler | [reply] |
'who' is your best bet, although the syntax you want is going to depend on your OS to some degree. i don't know what you'd be using netstat for. here's a chunk of code i use to get IP's under solaris and tru64/OSF1
OS=`uname`
if [ "$OS" = "SunOS" ]; then
IP=`who am i | cut -f 2 -d \( | cut -f 1 -d \)`
elif [ "$OS" = "OSF1"]; then
IP=`who -M am i | cut -f 2 -d \( | cut -f 1 -d \)`
fi
| [reply] [d/l] |
This may not be feasible in your situation, but
if you migrate from telnet to openssh, you'll get
an easily parsable SSH_CLIENT environment variable,
and a few other benefits as well.
$ env | grep SSH
SSH_TTY=/dev/pts/44
SSH_CLIENT=172.19.69.68 1850 22
| [reply] [d/l] |
Hmm, your question seems to require a list of the IP's. You can do this fairly easily on the server side with (whatever your OS's equivalent) the FreeBSD netstat -an command. Parsing the output for IP-Octet.IP-Octet.IP-Octet.IP-Octet.23 (23 being the telnet port) should not be to hard. There are even a couple CPAN modules that will help with easy IP Addr parsing.
Doing it this way is going to be much easier than a client side solution, IMHO.
"Nothing is sure but death and taxes" I say combine the two and its death to all taxes! | [reply] [d/l] [select] |