- IP address of remote end of telnet session
- Posted by Lars Oberg on February 16th, 2004
Hi,
I have been searching Google for a way to determine the ip address (not the
resolved name) of the remote end of a telnet session, but did not come
accross a working, simple way to accomplish this. But I did find many
people asking the question, so I figured I share the solution I came up
with:
S_TTY=$(who am i | awk ' { print $2; } ')
S_IP=$(last -i $S_TTY -n1 | head -1 | awk ' { print $3; } ')
S_IP will contain the ip address. This may not be not a perfect and portable
solution, but it works fine for me (on RH 7.x).
/ Lars
- Posted by Alan Connor on February 16th, 2004
On Mon, 16 Feb 2004 21:05:29 GMT, Lars Oberg <n-o-sp-am-lars_oberg@hotmail.com> wrote:
Good man, Lars. Belongs in the archives.
AC
--
ed(1) Check out the original tutorials by Brian W.
Kernighan at the Ed Home Page http://tinyurl.com/2aa6g
- Posted by Kirk Strauser on February 16th, 2004
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
At 2004-02-16T21:05:29Z, "Lars Oberg" <n-o-sp-am-lars_oberg@hotmail.com> writes:
Two problems:
1) It's definitely not portable. "-i" is unique to GNU "last".
2) Running it at home gave me "2001:470:1f01:22", which is only accurate
to 60 bits.
- --
Kirk Strauser
The Strauser Group
Open. Solutions. Simple.
http://www.strausergroup.com/
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.2.4 (GNU/Linux)
iD8DBQFAMUYc5sRg+Y0CpvERAly8AJ9GcgD6LJuxkTsSKcxvCJ AjdfOFvwCbBmbS
skrJitLqMAI93ii3P8x419Q=
=wD8J
-----END PGP SIGNATURE-----
- Posted by Lars Oberg on February 16th, 2004
Kirk,
Like I said, it may not be a perfect or portable solution, but it works fine
for me on RH 7.x, so I'm sharing it for whoever finds it useful.
If you have a better solution to share, please post it - I am sure there are
many users who could use a portable solution to this problem.
/ Lars
"Kirk Strauser" <kirk@strauser.com> wrote in message
news:878yj2bqib.fsf@strauser.com...
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
At 2004-02-16T21:05:29Z, "Lars Oberg" <n-o-sp-am-lars_oberg@hotmail.com>
writes:
Two problems:
1) It's definitely not portable. "-i" is unique to GNU "last".
2) Running it at home gave me "2001:470:1f01:22", which is only accurate
to 60 bits.
- --
Kirk Strauser
The Strauser Group
Open. Solutions. Simple.
http://www.strausergroup.com/
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.2.4 (GNU/Linux)
iD8DBQFAMUYc5sRg+Y0CpvERAly8AJ9GcgD6LJuxkTsSKcxvCJ AjdfOFvwCbBmbS
skrJitLqMAI93ii3P8x419Q=
=wD8J
-----END PGP SIGNATURE-----
- Posted by Kirk Strauser on February 17th, 2004
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
At 2004-02-17T00:01:57Z, "Lars Oberg" <n-o-sp-am-lars_oberg@hotmail.com> writes:
I understand and appreciate that, but I did want to point out to interested
parties that it's GNU-and-IPv4-only.
Well, what *exactly* is the question? That is, what problem is this trying
to solve?
- --
Kirk Strauser
The Strauser Group
Open. Solutions. Simple.
http://www.strausergroup.com/
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.2.4 (GNU/Linux)
iD8DBQFAMWdB5sRg+Y0CpvERAqlQAJ41MaN1MgoNUVIhYoWwlS R95bKD5gCeIXHc
X5/e/l9MHS5rsHDvzz+6Unw=
=a6Sr
-----END PGP SIGNATURE-----
- Posted by Lars Oberg on February 17th, 2004
"Kirk Strauser" <kirk@strauser.com> wrote in message
news:87d68e8qtg.fsf@strauser.com...
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
At 2004-02-17T00:01:57Z, "Lars Oberg" <n-o-sp-am-lars_oberg@hotmail.com>
writes:
Ok. Say you are logging into a Linux / Unix server using telnet. From your
login script or similar: How do you determine the IP address (not the
resolved name) of the workstation that initiated that telnet session to the
server. If you have a portable way of accomplishing this, I would be very
interested in it.
My specific use of knowing the remote IP address of each telnet session on
the server is to determine what location the workstation is coming from,
etc. (based on our internal IP numbering scheme).
/ Lars
- Posted by Kenny McCormack on February 17th, 2004
In article <YieYb.26212$yw3.960@newssvr25.news.prodigy.com> ,
Lars Oberg <n-o-sp-am-lars_oberg@hotmail.com> wrote:
....
The way you phrase this makes it sound like you *do* have a way to get the
"symbolic" name - and that your issue is converting that to the numeric
form.
If this is the case, you should take a look at the "host" command.
- Posted by Lars Oberg on February 17th, 2004
Thanks for the advice. No I do not have a reliable and portable way to get
the resolved name either.
Anyhow, unless anyone else has a better (more portable) solution, I will
just stick to the method I initially posted, since it works just fine on RH
7.x.
Thanks,
Lars