📜 ⬆️ ⬇️

Shutdown PC anywhere in the world (JAVA)

Hello!


I studied java, and I thought - (You sit in a toilet with a phone, and you have blood on your PC, murders and naked boobs are open, suddenly someone comes and says, “I will sit at the computer a bit, don't you mind?”) ” but what if you write a server program that turns off the PC when the user is connected to it. ” After this thought, I learned about such a thing as

runtime.getruntime().exec 

And in general, I decided to do something:

 /*     10000 - ,    ,   */ import java.io.IOException; import java.net.ServerSocket; public class Serv { public static void main(String[] args) throws IOException { ServerSocket serverSocket = new ServerSocket(10000); serverSocket.accept(); Process shutdown = Runtime.getRuntime().exec(new String[]{"shutdown", "-s" }); serverSocket.close(); } } 

It was the simplest option.

An improved version immediately followed (with sending html to the joining client):
')
 import java.io.IOException; import java.io.InputStream; import java.io.OutputStream; import java.net.ServerSocket; import java.net.Socket; public class Serv { public static void main(String[] args) throws IOException { int sPort = 9000; ServerSocket socket = new ServerSocket(sPort); Socket ss = socket.accept();//  -  System.out.println("CONNECTED"); OutputStream sout = ss.getOutputStream(); String html = "<html><head><title>Shutdown</title></head><body><h1>   15-20 !</h1><br/><img src = 'http://s.elitarium.ru/wp-content/uploads/1632841882.jpg'></br><h2>   :)</h2></body></html>";//html //       (^=◕ᴥ◕=^) String header = "HTTP/1.1 200 OK\nContent-type: text/html\nContent-Length: " + html.length() + "\nConnection: close\n\n";//html header String outputText = header + html; sout.write(outputText.getBytes()); String[] cm = { "shutdown", "-s" }; Runtime.getRuntime().exec(cm); ss.close(); socket.close(); } } 

Then I compiled this code in jar:
image

image

image

image

Program made.

After its launch, nothing special will happen, but now if you connect to port 9000 of your computer (I have 192.186.1.2:9000) on any other device connected to the same wi-fi, your computer will start shutting down.

proofs
image
image

After that, you can add it to the autorun and calmly use it within wi-fi ...

But I decided to press a little more, and make access to the 9,000 port from anywhere in the world (but this is not certain):

Open the settings of the router, we find there is something similar to that on the picchah and enter your data there:

image

Then we find out the external ip ( 2ip.ru to help), and connect to it via the port specified in the settings (for example, xxx.xxx.xxx.xxx:15).

PS: Since the internal computer ip can vary (depending on the number of devices connected to wi-fi), you can create mapping for several internal addresses at once (192.168.1.2, 192.168.1.3, 192.168.1.4 for example).

That's all.

PPS: If anyone needs this program -> google.drive

Source: https://habr.com/ru/post/341280/


All Articles