Solved

IP address from a pseudo-terminal device

Posted on 2000-02-19
11
319 Views
Last Modified: 2013-12-06
How can i find the IP address or the host name of people telneting to my UNIX machine. This is to be used in a shell script and should be clean. I.e i would prefer not to us finger or last.
I wish to use this in an application that will ftp results back to people who telnet into the UNIX application and who are running a ftpd on their PC's.
0
Comment
Question by:richardgraham
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 4
  • 3
11 Comments
 
LVL 14

Expert Comment

by:mcrider
ID: 2540363
Type in the command "who".

If should give you all of the users logged in.  Users telnet'ed in to your system will have the hostname at the end of their line... usually in parenthesis...

You can parse this in your shell script.


Cheers!
0
 
LVL 3

Expert Comment

by:klover
ID: 2541214
netstat -n|grep :23

will give you a list of all IPs currently attached to your Unix machine via telnet.
0
 
LVL 14

Expert Comment

by:mcrider
ID: 2541349
"who" gives the username and hostname...

"netstat -n|grep :23" gives the username and IP address


Cheers!
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 14

Expert Comment

by:mcrider
ID: 2541353
by the way, "who" also gives the pseudo terminal name, "netstat -n|grep :23" doesnt...


Cheers!
0
 
LVL 3

Expert Comment

by:klover
ID: 2541723
On my SCO OpenServer 5.0.5 box a "who" does not show the hostname or IP.  Checked the man, "w -x" is required to get the IP or hostname of the user.  

What flavor of Unix are you running?
0
 
LVL 3

Expert Comment

by:klover
ID: 2541771
My shell scripting is kind of weak but you could put something like this in the .profile or .login of the user ...

#set environment variable
MYTTY=sed<`tty`;export MYTTY

#set IP of user
IPADDR=sed <who -x|grep $MYTTY

#whatever other commands they run

#ftp them their files when done
ftp $IPADDR

Both sed commands would need some more work.  In the first one tty returns /dev/tty#, so you'd need to use sed (or awk?) to strip off the leading /dev/.  Then the who -x is going to return a whole line of info, so you'd need to strip out the IP somehow.
0
 
LVL 21

Expert Comment

by:tfewster
ID: 2548353
Try IPADDR=awk '{print $n}' < `who am i` in their .profile or .login

where n is the field number of the ip address (or hostname, if the address is in /etc/hosts) returned by `who am i`

Depending on your Unix, you may have to add options (e.g. -h) to the `who` command to get it to display the IP address/hostname
0
 
LVL 21

Expert Comment

by:tfewster
ID: 2559589
Oops - wrong way round; Should have said:

IPADDR=`who am i | awk '{print $n}'`

where n is the field number of the ip address (or hostname, if the address is in /etc/hosts) returned by `who am i`



0
 
LVL 14

Expert Comment

by:mcrider
ID: 2560426
tfewster, Please re-read the question again. your solution *does not* give the IP address of OTHER people connecting to the system...

Suggest you remove your answer...
0
 
LVL 21

Expert Comment

by:tfewster
ID: 2561068
mcrider, as I understand it richardgraham's requirement is to get the hostname/address of a particular user session, not just to see who's on the system, possibly with multiple logins. However, I've withdrawn my answer in case I've misunderstood.

richardgraham: In THEIR .profile/.login
IPADDR=`who am i | awk '{print $n}'|sed s/(//|sed s/)//` will return the "address" for that session. Alternatively, you could capture this info. when they run the application to save having to modify everyone's login scripts.

The sed statements i've added deal with the case that "who" returns a hostname (usually in parentheses). The parentheses in the sed statements may need to be "escaped" with \ to prevent them being interpreted by the shell.

If the expected usage is: User logs in, kicks off a query & then logs out, with results being ftp'd to them later, you will have to save their address & tie it to the query results file. Be warned though that automating ftp has it's own problems.





0
 
LVL 21

Accepted Solution

by:
tfewster earned 75 total points
ID: 2576255
See previous comments:
 
Solaris & AIX:  use `who -m |awk '{print $6}' | sed s/\(//|sed s/\)//`

HP-UX:use `who -m -u | awk '{print $8}'`

0

Featured Post

[Webinar] Learn How Hackers Steal Your Credentials

Do You Know How Hackers Steal Your Credentials? Join us and Skyport Systems to learn how hackers steal your credentials and why Active Directory must be secure to stop them. Thursday, July 13, 2017 10:00 A.M. PDT

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

When you do backups in the Solaris Operating System, the file system must be inactive. Otherwise, the output may be inconsistent. A file system is inactive when it's unmounted or it's write-locked by the operating system. Although the fssnap utility…
Every server (virtual or physical) needs a console: and the console can be provided through hardware directly connected, software for remote connections, local connections, through a KVM, etc. This document explains the different types of consol…
Learn how to get help with Linux/Unix bash shell commands. Use help to read help documents for built in bash shell commands.: Use man to interface with the online reference manuals for shell commands.: Use man to search man pages for unknown command…
Learn how to find files with the shell using the find and locate commands. Use locate to find a needle in a haystack.: With locate, check if the file still exists.: Use find to get the actual location of the file.:

688 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question