1

I'm writing a Python script to access all computers on the network, log in to them and read some log files. I don't want to use something as low-level as socket, but I can if I must. I realize that my problem is similar to this question, but not the same.

Are there any modules for accessing external Windows machines? Has anyone done anything like this before?

I'm specifically looking to log into Windows 7 machines, not unix.

Let's also assume that each computer I want to log into has Remote Desktop installed and enabled. I'm also not worried about network security or encryption because these files are not confidential. Windows machines don't have SSH installed on the by default do they?

Community
  • 1
  • 1
Jeffrey Greenham
  • 1,382
  • 5
  • 16
  • 33
  • And you work on what? I am comunicating with XP and W7. Folders have to be shared. – f p May 30 '12 at 17:21

3 Answers3

3

There has to be something on the other side for you to talk to. This limits you to either setting up a "server" on each machine, installing a real server (i.e. sshd), building a "server" yourself and installing it, or using a built in and active feature of the OS.

Based upon this, what kind of system do you want to set up on these machines? What does it need to do? Just read the contents of a prespecified file list? Will that list change?

  • One solution is to turn on telnet, and use paramiko or twisted to talk across it. This isn't very secure of course
  • Next up, set up a samba share, and access the folder remotely. This is also insecure, though less so than telnet
  • You could find a ssh daemon port and run that, if you are so inclined
  • Psexec from sysinternals might work
  • Use twisted to build a server app with the features you need
  • Use ncat to listen on a port and spawn a cmd prompt

Be aware that most of the solutions for accessing windows remotely are... poor. The best solution is probably to roll your own, but that is hard work and you will probably make mistakes.

Also, Windows 7 is not exactly multi-user friendly. Individual processes can run as separate users, but the OS does not support having multiple users logged in at the same time. Someone is going to be the "user" and everyone else is just a process with a different credential set.

This is more an artificial limitation on M$'s part than anything technical. To see this in action, try to log in with RDP while a user is logged in locally. Fun times.

Per your edit, the easiest thing to do is just set up a samba share on the box.

After this share is set up:

with open(r'\\myCompNameOrIP\C\windows\logs\logfile.txt','rb') as logfile:
    loglines = logfile.readlines()

Or you can use the gencat sample found here. Just give it r'\\myCompNameOrIP\C\windows\logs\*.txt' as the search path and watch the magic.

Spencer Rathbun
  • 14,510
  • 6
  • 54
  • 73
0

From Ubuntu I use samba:

In Bash: gvfs-mount smb://them/folder

Here I give name, domain and password

Then in python:

folder = '/home/me/.gvfs/folder on them'

using the os module I read folders and files inside.

I am working in a small business environment.

f p
  • 3,165
  • 1
  • 27
  • 35
0

Why not have each of the computers send the log file to the central computer?