Python - detect if the remote computer is turned on

So, I have a Python application, but I want to know if the computer (which runs the application) is turned on from another remote computer.

Is there any way to do this? I was thinking of using UDP packets to send some kind of content using a counter. Ex. every 5 minutes, the client sends a keep-alive UDP packet to the server. Thanks in advance!

+7
python udp heartbeat
source share
5 answers

If your goal is to check if a particular service is running on a remote computer, you can check if the network port for which this service should work is available. Example:

import socket s = socket.socket(socket.AF_INET, socket.SOCK_STREAM) try: s.connect(('hostname', 22)) print "Port 22 reachable" except socket.error as e: print "Error on connect: %s" % e s.close() 

If the application you want to test is intended to run, for example, port 1337, then check this port.

+17
source share

First you need to know that there is no standard way to determine if a computer is turned on or not, and this does not depend on the language / platform. The computer can fake any state that you are trying to check.

But the usual way to check if the computer is turned on is Ping (ICMP Echo Request). This answer shows how to send Ping using Python.

+3
source share

It seems that you are looking for a network / host monitoring tool or just a simple heart rate monitor. Depending on the specifics (for example, the number of hosts to monitor), something like Nagios , Munin, or Heartbeat may help.

0
source share

yes, that’s the way. kinda like sending a heartbeat ping. With its UDP and with its simple header message, you can reduce the frequency to say 10 seconds. This should not lead to a deterioration in the quality of a measurable system, since we are talking only about the two systems that we are talking about.

I feel that UDP may be better than TCP. Its light weight, does not consume a lot of system resources and is theoretically faster. The downside may be packet loss. You can get around this by introducing some logic, for example, when 10 packets (at a distance of 10 seconds from each other) are not received sequentially, and then declare another system unavailable.

0
source share

Add a web server to your application.

http://www.tornadoweb.org/en/stable/ http://webpy.org/

0
source share

All Articles