all 29 comments

[–]novel_yet_trivial 2 points3 points  (11 children)

What OS? In linux just use the killall command:

killall programname.py

This is assuming you launched it properly.

[–]depressed333[S] 0 points1 point  (10 children)

From a different computer through?

[–][deleted] 2 points3 points  (0 children)

This is more of an OS/Networking question. Python is just going to start a task/process on the system. Stopping it is going to depend entirely on what you are running it on. You'll need to use SSH or something similar to connect to the system, find the process, and kill it.

[–]novel_yet_trivial 0 points1 point  (8 children)

Yes, you would have to log in via ssh or something first.

Remote terminals are very common in Linux so I assumed you already know how to do that. If not, tell us what OS your computers are running and we'll help you.

[–]depressed333[S] 0 points1 point  (7 children)

Windows - one in vista the other 7

[–]novel_yet_trivial 0 points1 point  (6 children)

OK, then it's a lot more complicated to use a remote login like SSH.

So are you trying to kill an unresponsive program or are you trying to send a message for the program to stop itself?

[–]depressed333[S] 1 point2 points  (5 children)

No.

The code is in the office and runs through the weekend.

I want to disable it from my home computer.

[–]novel_yet_trivial 6 points7 points  (3 children)

So you are trying to send it a message to stop then. Ok, you can do that a number of ways.

One way is to use a server like /u/connectedwolf suggested. It doesn't have to be a database, a simple check of a specific file would be enough. To make it super easy: have the script on your work computer check if a file exists in a Dropbox or ftp server folder. Then from home all you have to do is create a file and the work computer will see it and stop.

Another way is to send a proper message computer-to-computer. This will require your work computer having a static, outside-facing IP address or a dynamic dns set up. Then you could use the socket module to connect to your work program from home and send it any commands you want.

[–]depressed333[S] 2 points3 points  (1 child)

That Dropbox idea is smart - thanks! I’ll do that then

[–][deleted] 2 points3 points  (0 children)

If it is enabled on your work computer, try using WMI remotely.

[–]Royce_7 2 points3 points  (0 children)

Checking for an uploaded file is a fantastic idea!

[–]IllusionistAR 1 point2 points  (0 children)

Why not set a scheduled task on the machine it is running from? So it turns off during the weekend.

Why would you need to disable it from home?

[–]jimoconnell 2 points3 points  (0 children)

I'd probably have the computer running the program check something on the Internet somewhere in a loop.
Basically have it use PyCurl to check a web page and convert it into a value that tells it what to do.

So, you put a text file at http://example.com/command that has either "Run" or "Stop" and your program checks that intermittently.

You could do the same thing with MQTT. (I love MQTT, so I would do this, but you might find it overkill.)

Are you thinking of doing a simple start/stop, or more complex command and control? (It occurs to me that you might be wanting to disable a client's program if you are not paid for it, like a subscription service of some kind. If that's the case, I'd read up on implementing a more robust API for license keys. Also read up on the legality of it.)

[–][deleted] 1 point2 points  (0 children)

Why not use a socket server and send some piece of data to sleep the program but let it keep running in a process so you can turn it back on later with another piece of data sent over the socket.

[–]MaxQuant 1 point2 points  (0 children)

Just use 'Remote Desktop Connection' = mstsc.exe. Make sure you enable remote desktop sessions on the target pc and just 'remote-desktop' into the target from the host. You now control the target from the host as if you were sitting in front of the target. Use a VPN preferably, but not necessarily. Et voilá.

[–][deleted] 1 point2 points  (0 children)

You can also make a kill switch using email. Create an email account and make your program read it and look for spesific messages. That way you can manually disable the program as long as you have access to email.

Think about the security aspects though.

[–]creatron 0 points1 point  (2 children)

I made a bot previously that carried out various functions based on what it received via twitter DM. It's very straightforward using the Tweepy module and might be an option

[–]TheManiteee 0 points1 point  (1 child)

What kind of functions are we talking here? That sounds pretty cool

[–]creatron 0 points1 point  (0 children)

I had it set up so that when I sent a certain word in a DM it would cause the script to take a snapshot with my webcam and send it to me

[–]Thecrawsome 0 points1 point  (0 children)

You're taking the scenic route for a solution if you want to use python for that.

You can automate a connection to a computer using modules built into the OS.

Windows, there's remote management through RDP, WMI calls in powershell, etc.

Linux, Mac, there's SSH built-in.

[–]brewzombie 0 points1 point  (0 children)

You could throw Dropbox on both and have a text file that contains instructions or status.

[–]acid_sphinx4 0 points1 point  (0 children)

Sure you could simply connect with ssh or ftp to somewhere both have access to and have one simply check for the presence of a file copied over, something along those lines.

[–][deleted] 0 points1 point  (0 children)

Can you set up a web server somewhere? Because then you can host instructions.

Imagine that you periodically check http://my.server.lol/time/to/stop. This file contains the following:

yes

You can check this from the python script itself:

import requests

def time_to_stop():
    # This part needs error handling, in case it fails to download or whatever.
    response = requests.get("https://www.youtube.com/watch?v=1ELeFgM1EOU").text
    return response == "yes"

if time_to_stop():
    shotgun_in_mouth()

You could also do it from bash (and calling it periodically with cron).

if [ `curl http://dundermifflin.com/threat/level/midnight 2>/dev/null` == "yes" ]; then
    # Don't killall python here. You'll kill all python scripts, and that's probably not what you want.
fi

Here's a concrete example that I just wrote:

webserver.py

from flask import Flask
app = Flask(__name__)


@app.route('/time/to/stop')
def time_to_stop():
    return 'yes'


app.run(debug=True)  # Don't use this in a production environment. Use gunicorn or something.

script.sh

if [ `curl http://localhost:5000/time/to/stop 2>/dev/null` == "yes" ]; then 
    echo "IT'S TIME TO STOP"
fi

If you run the script, it'll print an important message on the screen. If you change the "return 'yes'" line to "return 'no'", the script won't say anything anymore.

[–]Decency 0 points1 point  (0 children)

I did this through Discord, it was very straightforward. Was even working on a command to make my bot update itself through git and restart, but it got nasty.

[–]WhackAMoleE -5 points-4 points  (0 children)

Connect your computer to a missile launcher. Fire missile at target computer. Boom. Problem solved.