Is there a way to find out who is logged in to another Linux machine on the network given the machine name and not just sshing into that machine and running
who? I'd prefer a way directly in python, but through a command would be fine.
You could set up a service that does this for you on the remote machine and simply return the result; or you write a script that does the whole procedure for you. But I don't see why anyone outside (outside of the machine) should be able to access system information without logging in (and as soon as you log in you can use SSH instead).
It depends, things need to be set up to allow you to do this. One possibility is 'rusers'
If your preference is to do your ssh op's programatically via python then you should look at paramiko, a native python ssh library.
There's a good over view article here
I actually looked at this question and all answers are non python. The best thing I found online is psutil. See the documentation psutil on Google Code
First install psutil :
pip install psutil
After that everything is easy as an example run python console from terminal:
import psutil psutil.users()
Here's the output: [user(name='root', terminal='pts/0', host='your-local-host-from-isp.net', started=1358152704.0)]
Short answer: Not unless the machine is specifically set up for it.
Long answer: The machine would need to be running a service on a known port that you could connect to to query this information. An alternative is to use pexpect to programmatically ssh into the machine, run
who and parse the results.
A tricky way would be to find a way to derive the information from a directory service. Many, many people have Enterprise systems with their authorized user list/password management coming from ActiveDirectory. If you could find a way to pair your question with the Kerberos Ticket Granting Ticket service, along with short-lived tickets, it just might be possible to at least infer who is probably logged in. If the system tells the directory service when a user logs out, things are a little easier.
You probably wanted the answer "finger" though and just didn't know it. Where finger went wrong though was when it started letting users create a
$HOME/.finger because all kinds of problems erupted from that (named pipes and so on). Additionally, the finger protocol had some serious flaws that allowed for the usual buffer overflows, etc. Some paranoid folks consider that even listing the user IDs or user names of valid users provides an attack vector. If you could scan the network looking for the system a lead researcher used, that's a machine with access to lots of material ripe for industrial espionage.
Another interesting trick would be to have the system notify a central service whenever a user connected or disconnected. Think an IRC bot, chat server, or a REST service. Any process could periodically look for interactive sessions and submit the information in a one-way kind of fashion to an application on the other end. This application would then collate the feed to present a list of who is on "the network" to a web page. If this is for interesting business or education programs, it could be quite interesting because you could even log in users coming in through a web application like webmail.