Solved

IP address from a pseudo-terminal device

Posted on 2000-02-19
11
315 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
  • 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
PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

 
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 20

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 20

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 20

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 20

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

Netscaler Common Configuration How To guides

If you use NetScaler you will want to see these guides. The NetScaler How To Guides show administrators how to get NetScaler up and configured by providing instructions for common scenarios and some not so common ones.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Audit HISTFILE for all users on AIX 9 133
how to monitor remote shell execution on linux 9 100
MarkLogic 1 79
Linux "time" command output redirection 16 148
In tuning file systems on the Solaris Operating System, changing some parameters of a file system usually destroys the data on it. For instance, changing the cache segment block size in the volume of a T3 requires that you delete the existing volu…
FreeBSD on EC2 FreeBSD (https://www.freebsd.org) is a robust Unix-like operating system that has been around for many years. FreeBSD is available on Amazon EC2 through Amazon Machine Images (AMIs) provided by FreeBSD developer and security office…
This video shows how to set up a shell script to accept a positional parameter when called, pass that to a SQL script, accept the output from the statement back and then manipulate it in the Shell.
In a previous video, we went over how to export a DynamoDB table into Amazon S3.  In this video, we show how to load the export from S3 into a DynamoDB table.

803 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