By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,275 Members | 1,031 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,275 IT Pros & Developers. It's quick & easy.

How to ping and shutdown a remote computer?

P: n/a
I am working on a Python script to perform as a remote computer
manager. So far I have a WOL function working and I would like to add
the ability to show if a machine is on or off (I figured I would do so
by pinging the machine and seeing if I get a response). I would also
like to add the ability to remotely shutdown a computer from the
python script. Does anyone have a code snippet for pinging an IP, a
code snippet for shutting down a remote Windows XP machine, and a code
snippet for sending a HTTP request?

Here is my current setup:

- PC running python script
- FreeNAS (media server running on FreeBSD. Can be shutdown from web
interface so I planned on just sending that same web button click from
the python script to shutdown the FreeNAS server)
- Windows XP machine with folder share (What packet is sent over the
network to remotely shutdown a Windows XP machine?)

My hope is to have a script then when you start it will list all your
remote computers/servers and show if they are currently on/off. Then
you can select a server and turn it off if it is on or turn it on if
it is off.

Thank you in advance for any help provided.

- John

Feb 14 '07 #1
Share this Question
Share on Google+
3 Replies


P: n/a
jo****@gmail.com a écrit :
I am working on a Python script to perform as a remote computer
manager. So far I have a WOL function working and I would like to add
the ability to show if a machine is on or off (I figured I would do so
by pinging the machine and seeing if I get a response). I would also
like to add the ability to remotely shutdown a computer from the
python script. Does anyone have a code snippet for pinging an IP, a
code snippet for shutting down a remote Windows XP machine, and a code
snippet for sending a HTTP request?

Here is my current setup:

- PC running python script
- FreeNAS (media server running on FreeBSD. Can be shutdown from web
interface so I planned on just sending that same web button click from
the python script to shutdown the FreeNAS server)
- Windows XP machine with folder share (What packet is sent over the
network to remotely shutdown a Windows XP machine?)
import os
os.system("shutdown -s -f")
Try other switches if you want. Requires Windows XP at the minimum.
Feb 14 '07 #2

P: n/a
jo****@gmail.com wrote:
Here is my current setup:

[... BSD ...]
- Windows XP machine with folder share (What packet is sent over the
network to remotely shutdown a Windows XP machine?)

My hope is to have a script then when you start it will list all your
remote computers/servers and show if they are currently on/off. Then
you can select a server and turn it off if it is on or turn it on if
it is off.
Couple of bits of info, speaking only about Windows. First, I'd
be quite worried if someone could send me a packet (maliciously
or otherwise) which simply shut my machine down. Is this possible?
Second, machines -- or networks -- may be configured to reject
or swallow pings so the lack of a ping may not indicate vitality.

Since you specify that the machine has a folder share, that means
it's running SMB/NMB/whatever it's called across a few well-known
ports, including 135 and 137-139 and 445. So you could attempt a
socket connection to one of those:

<code>
import socket
s = socket.socket ()
s.settimeout (0.25)
try:
s.connect (("192.168.100.84", 135))
except socket.error:
print "not alive"
else:
print "alive"

</code>

To shut it down, someone has already suggested the
shutdown command, although I think you'd have to
specify the -m param to pass the remote machine name.
Alternatively, you could use WMI (which inadvertently
provides a means of determining vitality):

http://timgolden.me.uk/python/wmi_co...remote_machine

(adapted a bit, but you get the idea)

TJG
Feb 14 '07 #3

P: n/a
On Feb 14, 10:09 am, Christophe <chris.cavala...@free.frwrote:
joj...@gmail.com a écrit :
I am working on a Python script to perform as a remote computer
manager. So far I have a WOL function working and I would like to add
the ability to show if a machine is on or off (I figured I would do so
by pinging the machine and seeing if I get a response). I would also
like to add the ability to remotely shutdown a computer from the
python script. Does anyone have a code snippet for pinging an IP, a
code snippet for shutting down a remote Windows XP machine, and a code
snippet for sending a HTTP request?
Here is my current setup:
- PC running python script
- FreeNAS (media server running on FreeBSD. Can be shutdown from web
interface so I planned on just sending that same web button click from
the python script to shutdown the FreeNAS server)
- Windows XP machine with folder share (What packet is sent over the
network to remotely shutdown a Windows XP machine?)

import os
os.system("shutdown -s -f")
Try other switches if you want. Requires Windows XP at the minimum.
That is a good idea but I don't have Windows XP on the machine
performing the shutdown. I should have been more detailed. I said PC
but what it is is a Xbox running XBMC: http://www.xboxmediacenter.com

I should have been more detailed in that.

- John

Feb 14 '07 #4

This discussion thread is closed

Replies have been disabled for this discussion.