Sie sind auf Seite 1von 6

#!/usr/bin/env python # -*- coding: utf-8 -*import sys print """ \033[91m ############################################################ # ____ _____________.

______________________ # # \ \ / / _____/| \______ \_ ___ \ # # \ Y /\_____ \ | || _/ \ \/ # # \ / / \| || | \ \____ # # \___/ /_______ /|___||____|_ /\______ / # # \/ \/ \/ # ############################################################ \033[92m ############################################################ #### WELCOME TO THE VERYSIMPLEIRCCLIENT #### #### ENJOY YOUR ABSOL00T FREEDOM FROM VULNS ETC. #### #### THIS APP DOES NOT SEND ANYTAN YOU DO NOT TYPE!!! #### ############################################################ - Programmed and absolutely not maintained by WebPunk.dk - Feel free to modify, redistribute or delete this script. - No licensing apply to this piece of software. - Ctrl +C dies this application :-) """ import threading import time import os import socket import sys class VSIRCClient(threading.Thread): def __init__(self, lock): threading.Thread.__init__(self) self.lock = lock self.stopped = False self.remoteHost = "" self.userList = "" self.nickName = "" self.channelName = "" self.connectedFlag = False def run(self): if self.connectedFlag: self.mainLoop() else: sys.exit(1) def connect(self, host): self.host = host print "\033[33mVSIRC: \033[91mTrying to connect to " + host + "...." try: self.ircSocket = socket.socket() self.ircSocket.connect((host,6667)) #self.logFile = open("log.log", "w") print "\033[33mVSIRC: \033[92mSocket Connection succesfull" self.connectedFlag = True

self.ircSocket.setblocking(0) time.sleep(1) self.sendLogin(self.nickName, "Random Dude") return True except: print "\033[33mVSIRC: \033[91mSocket connection failed... Enter to e xit!\033[0m" self.stopped = True self.connectedFlag = False return False def sendLogin(self, nickName, realName): print "\033[33mVSIRC: \033[92mSending USER AND NICK" self.ircSocket.send("USER Random Dude 8 * : " + realName + "\r\n") self.ircSocket.send("NICK " + nickName + "\r\n") self.nick = nickName def connected(self): return self.connectedFlag def mainLoop(self): print "\033[33mVSIRC: \033[92mStarting main message loop(Send with ""Ent er"" CTRL +C exits)" lineBuffer = "" charBuffer = "" while self.stopped == False: endTrans = False try: while not endTrans: charBuffer = self.ircSocket.recv(1) lineBuffer += charBuffer except: endTrans = True with lock: if lineBuffer != "": tmpLineArr = lineBuffer.split("\r\n") for line in tmpLineArr: try: ResponseTmp = self.parseResponse(line).replace(u"\u0 002", "").replace(u"\u0003", "") if ResponseTmp != "": print ResponseTmp except: print "ERROR" #time.sleep(2) lineBuffer = "" def sendPong(self, pingRecv): pingArr = pingRecv.split(":") self.ircSocket.send("PONG :" + pingArr[len(pingArr)-1] + "\r\n") def parseResponse(self, response): if response != "": try:

responseList = response.split(":") paramsList = responseList[1].split(" ") msg = "" count = 0 while count < len(responseList): if count > 1: msg += responseList[count] count += 1 if "NOTICE" in responseList[1]: #Gem hosten i en self.remoteHost self.remoteHost = paramsList[0] #Parse server NOTICE return "\033[33m" + paramsList[0] + ": \033[0m" + msg elif "PING" in response.upper(): self.sendPong(response) return "\033[33mVSIRC: \033[92m" + "PING recieved, PONG sen d." elif "332" in responseList[1]: #TOPIC self.channelName = paramsList[len(paramsList)-2] return "\n\033[0mTOPIC for the channel " + self.channelName. upper() + ":\n\033[92m" + msg + "\033[92m" elif "353" in responseList[1]: #USER LIST if self.userList == "": print "\033[0m" + "USERS currently in " + self.channelNa me.upper() + ":\033[92m" self.userList += msg return "" #\033[92m" + msg elif "366" in responseList[1]: # End of usr list return self.userList.replace("\r\n", "") elif "372" in responseList[1]: #MOTD return "\033[91m" + msg elif "403" in responseList[1] or "401" in responseList[1]: return "\033[33mVSIRC: \033[92m" + "No such nick/channel" elif "433" in responseList[1]: return "\033[33mVSIRC: \033[92m" + "Nickname already exists, exit with CTRL +C." self.stopped = True sys.exit(1) elif "JOIN" in responseList[1].upper(): nickJoined = paramsList[0].split("!") nickJoined = nickJoined[0] chanJoined = responseList[1].split(" ") chanJoined = chanJoined[len(chanJoined)-1] if self.nick in nickJoined: self.channelName = chanJoined return "\033[33mVSIRC: \033[91m" + nickJoined + "\033[0m JOI NED \033[92m" + chanJoined elif "PART" in responseList[1].upper():

nickLeaved = paramsList[0].split("!") nickLeaved = nickLeaved[0] chanLeft = responseList[1].split(" ") chanLeft = chanLeft[len(chanLeft)-1] if self.nick in nickLeaved: self.channelName = "" #return responseList[1].upper() self.userList = "" return "\033[33mVSIRC: \033[91m" + nickLeaved + "\033[0m LEF T \033[92m" + chanLeft elif "PRIVMSG" in responseList[1].upper(): #MSG nickSaying = paramsList[0].split("!") nickSaying = nickSaying[0] if self.nick in responseList[1]: return "\033[91m" + nickSaying + ": \033[92m" + msg else: return "\033[33m" + nickSaying + ": \033[92m" + msg else: return "" #response except Exception, err: #print sys.exc_info() #<- uncomment to print exceptions return "" else: return "" def sendMsg(self, msg): userCommand = msg[:2].lower() if "/j" in userCommand: #JOIN try: if self.channelName == "": chanName = msg.split("#") chanName = "#" + chanName[1] self.ircSocket.send("JOIN " + chanName + "\r\n") self.channelName = chanName else: print "\033[33mVSIRC: \033[92m - SRY, but this is a SIMPLE i rc client, u cant join multiple chans" except: print "\033[33mVSIRC: \033[92m - Wrong format channame, (#Channa me) is OK!" elif "/l" in userCommand: #LEAVE if self.channelName != "": self.ircSocket.send("PART " + self.channelName + " :\r\n") self.channelName = "" else: print "\033[33mVSIRC: \033[92m - Not in any channel!" elif "/m" in userCommand: #PRIVATE MSG TO USER msgList = msg.split(" ") userMsg = "" count = 2 while count < len(msgList): userMsg += msgList[count] + " " count += 1 try: self.ircSocket.send("PRIVMSG " + msgList[1] + " :" + userMsg

+ "\r\n") except: print "\033[33mVSIRC: \033[92m - Wrong format privmsg, (/pri v [nick] [message]) is OK!" elif "/q" in userCommand: #Quit self.ircSocket.send("QUIT\r\n") print "\033[33mVSIRC: \033[92m" + "Closing connection....\033[0m" self.stopped = True sys.exit(1) else: self.ircSocket.send("PRIVMSG " + self.channelName + " :" + msg + "\r \n") def stop(self): self.ircSocket.shutdown(socket.SHUT_RDWR) self.ircSocket.close() print "\033[33mVSIRC: \033[92mStopping main message loop" self.stopped = True if __name__ == "__main__": lock = threading.Lock() ClientThread = VSIRCClient(lock) try: userArg = sys.argv[2] # hvis der ikke er to args, s vis hjlp! except: #ingen userArgs userArg = "" if userArg == "" or userArg == "help": print """ ############################################################ \033[91m- ERROR - MISSING COMMAND LINE ARGUMENTS \033[33m- HELP FILE FOR VSIRC: H.vsirc - COMMAND LINE USAGE: Vsirc.py [Nick] [Server]\033[92m ############################################################ """ sys.exit() else: ClientThread.nickName = sys.argv[1] print "\033[33mVSIRC: \033[92mSetting desired NICK to " + ClientThread.n ickName ClientThread.connect(sys.argv[2]) ClientThread.start() while True: try: os.system("stty -echo") raw_input("") os.system("stty echo") with lock: if ClientThread.connected(): userInput = raw_input("\033[33m" + ClientThread.nick + "->\0 33[92m ") ClientThread.sendMsg(userInput) else:

sys.exit() except KeyboardInterrupt: ClientThread.stop() os.system("stty echo") print "\033[33mVSIRC: \033[92m - Bye bye" print "\033[0m" break

Das könnte Ihnen auch gefallen