Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Python - Detect if remote computer is on

So, I have an application in Python, but I want to know if the computer (which is running the application) is on, from another remote computer.

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

like image 672
jndok Avatar asked Jul 16 '13 17:07

jndok


People also ask

How do I run a python script on a remote computer?

Create a copy of the remote file on the local computer and open it in Visual Studio. It doesn't matter where the file is located, but its name should match the name of the script on the remote computer. (Optional) To have IntelliSense for ptvsd on your local computer, install the ptvsd package into your Python environment.

How do I debug Python code on a remote computer?

A remote computer running Python on an operating system like Mac OSX or Linux. Port 5678 (inbound) opened on that computer's firewall, which is the default for remote debugging.

How do I run Python on azure remotely?

A remote computer running Python on an operating system like Mac OSX or Linux. Port 5678 (inbound) opened on that computer's firewall, which is the default for remote debugging. You can easily create a Linux virtual machine on Azure and access it using Remote Desktop from Windows.

How to check the internet connection in Python?

Below we have described two methods of checking the internet connection in Python. To fetch URLs, we use urllib.request module in Python. This can fetch URLs using a variety of different protocols. One of the functions present in the package are urllib.request.urlopen ().


1 Answers

If your goal actually is to test whether a specific service is running on the remote machine, you could test if the network port that this service should run on is reachable. 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 for is designed to run on e.g. port 1337, then check this port.

like image 93
Dr. Jan-Philip Gehrcke Avatar answered Oct 22 '22 03:10

Dr. Jan-Philip Gehrcke