def topicStuff(server,i,otherStuff): #:irc.archerseven.com 332 Nyx28 #Nyx :The Nyx channel #:[email protected] TOPIC #ogame :This is the ogame channel, talk about ogame battles and look for ogame help here.... #:irc.archerseven.com 333 Nyx28 #ogame dom96 1252250064 if len(i.split(" ")) > 1: msgCode=i.split(" ")[1] else: return datParsed = ResponseParser.parseServerRegex(i)[0] if msgCode == "332": for ch in server.channels: if ch.cName == datParsed.channel: ch.cTopic = datParsed.msg for event in IRC.eventFunctions: if event.eventName == "onTopicChange" and event.cServer == server: gobject.idle_add(event.aFunc,datParsed,server,otherStuff) elif msgCode == "333": for event in IRC.eventFunctions: if event.eventName == "onTopicChange" and event.cServer == server: gobject.idle_add(event.aFunc,datParsed,server,otherStuff) elif "TOPIC" in i: m = ResponseParser.parseMsg(i,False) if m.typeMsg == "TOPIC": for ch in server.channels: if ch.cName == m.channel: ch.cTopic = m.msg for event in IRC.eventFunctions: if event.eventName == "onTopicChange" and event.cServer == server: gobject.idle_add(event.aFunc,m,server,otherStuff)
def motdStuff(server, i, otherStuff):#MOTD stuff global MOTDStarted global MOTD if len(i.split(" ")) > 1: msgCode = i.split(" ")[1] else: return #!--MOTD STUFF--!# #MOTD Start code, now i need to add the whole MOTD to one string until the MOTD END(376) if ("375" == msgCode): MOTDStarted = True MOTD = "" #Make sure it's a 376 message and that the message doesn't contain PRIVMSG or NOTICE, #couse if the PRIVMSG or notice contains 376 it's gonna print the MOTD again elif ("376" == msgCode): MOTDStarted = False MOTD += "\n" + i pResp = ResponseParser.parse(MOTD,True,True) server.cMotd = pResp #Call all the onMotdMsg events for event in IRC.eventFunctions: if event.eventName == "onMotdMsg" and event.cServer == server: gobject.idle_add(event.aFunc, pResp, server, otherStuff) #If MOTD is started (--and the code is 372--), add the motd to the MOTD string. if MOTDStarted == True and msgCode == "372": if i.startswith(":"): MOTD += "\n" MOTD += i
def kickResp(server,i,otherStuff): if "KICK" in i: m = ResponseParser.parseKick(i) if m is not False: if m.typeMsg == "KICK": for event in IRC.eventFunctions: if event.eventName == "onKickMsg" and event.cServer == server: gobject.idle_add(event.aFunc,m,server,otherStuff) try: #Delete the user who got kicked. for ch in server.channels: if ch.cName.lower() == m.channel.lower(): for usr in ch.cUsers: #m.nick is the nick that got kicked and the nick who kicked the user #totally forgot... personWhoWasKicked = m.nick.split(",")[1] if usr.cNick.lower() == personWhoWasKicked.lower(): pDebug("\033[1;32mRemoving %s from %s\033[1;m" % (personWhoWasKicked,ch.cName)) cTreeIter = usr.cTreeIter ch.cUsers.remove(usr) #Call the onUserRemove event for event in IRC.eventFunctions: if event.eventName == "onUserRemove" and event.cServer == server: gobject.idle_add(event.aFunc,ch,server,cTreeIter,None) except: traceback.print_exc()
def nickResp(server,i,otherStuff): if "NICK" in i: m = ResponseParser.parseMsg(i,True) if m is not False: if m.typeMsg == "NICK": #If the person who changed their nick is you, change the nick in the server. if m.nick == server.cNick: server.cNick = str(m.msg) for ch in server.channels: for usr in ch.cUsers: if usr.cNick.lower() == m.nick.lower(): pDebug(usr.cTreeIter) cTreeIter = usr.cTreeIter for event in IRC.eventFunctions: if event.eventName == "onUserRemove" and event.cServer == server: gobject.idle_add(event.aFunc,ch,server,cTreeIter,None) for ch in server.channels: for usr in ch.cUsers: if usr.cNick.lower() == m.nick.lower(): usr.cNick = m.msg cIndex = findIndex(usr,server,ch) for event in IRC.eventFunctions: if event.eventName == "onUserJoin" and event.cServer == server: event.aFunc(ch,server,cIndex,usr) #Might couse some random SEGFAULTS!!!!!!!!!!!!!! pDebug("NICK----" + m.nick + " = " + m.msg) for event in IRC.eventFunctions: if event.eventName == "onNickChange" and event.cServer == server: gobject.idle_add(event.aFunc,m,server,otherStuff)
def servResp(server, i, otherStuff): #Split into new lines \n splitNewLines = i.split("\n") for m in splitNewLines: splitI = i.split(" ") try: if (splitI[1] in numericCode()): datParsed = ResponseParser.parseServerRegex(i) #Some stuff that has to be done, e.g.433(Nickname already in use), 432(Nickname reserved for someone...? Like ChanServ) if splitI[1] == "433" or splitI[1] == "432": #If the MOTD has been received that means the user connected if server.cMotd == None: #Loop through the nicks to check which nick was #used, which will give you the next one to use. for i in range(0,len(server.nicks)): if server.nicks[i] == server.cNick: if len(server.nicks) != i + 1: server.cNick = server.nicks[i+1] else: #If there is no more alternative nicks #left make a random one. import random server.cNick = "r" + str(hash(str(random.randint(0,200)))).replace("-","") #Send a raw command, NICK <NewNick> pDebug("\033[1;34mNICK " + server.cNick + "\\r\\n\033[1;m") server.cSocket.send("NICK " + server.cNick + "\r\n") break for event in IRC.eventFunctions: if event.eventName == "onServerMsg" and event.cServer == server: gobject.idle_add(event.aFunc,datParsed,server,otherStuff) except: pDebug("\033[1;40m\033[1;33mIndex out of range-servResp\033[1;m\033[1;m")
def printResults(ip, verbose, accurate, output): if accurate: webbrowser.get('firefox').open( 'https://whatismyipaddress.com/ip/{0}'.format(ip)) if output: sys.stderr.write( '[-] Cannot write results when working in high accuracy mode\n' ) return rp = ResponseParser.ResponseParser(verbose) data = rp.GetParsedData(ip) print('\n\n') printBannerPadding() print('\n\n') print('[*] Tracing {0}'.format(ip)) if output: output.write( '================================================================\n\n' ) output.write(' Tracing {0}\n\n'.format(ip)) print('\n[*] Trace') genkeys = data.keys() for key in genkeys: print('[*] {0} : {1}'.format(key, data[key])) if output: output.write('{0} : {1}\n'.format(key, data[key])) if 'org' in data.keys(): return data['city'], data['lat'], data['lon'], data['org'] else: return data['city'], data['lat'], data['lon'], 'Unknown'
def joinResp(server,i,otherStuff):#The join message #!--JOIN MSG--!# if "JOIN" in i: m = ResponseParser.parseMsg(i,False) if m is not False: #Make sure it's a JOIN msg. if m.typeMsg == "JOIN": #If it's you that JOINed, check if there is a TreeIter already for this channel #and if not then add one. if m.nick.lower() == server.cNick.lower(): addNewUser=True #Check if there is already a channel created... for ch in server.channels: if ch.cName == m.channel: addNewUser=False if addNewUser==True: nChannel = IRC.channel() nChannel.cName = m.channel nChannel.cTextBuffer = gtk.TextBuffer() nChannel.UserListStore = gtk.ListStore(str,str) try: nChannel.cTreeIter = server.listTreeStore.append(server.cTreeIter, \ [m.channel, None, otherStuff.settings.normalTColor, "channel"]) except: import traceback; traceback.print_exc() nChannel.cMsgBuffer = [] #This fixes the weird problem with the queue being in the wrong channel. #Add the newly JOINed channel to the Servers channel list server.channels.append(nChannel) #Send the MODE message, to ask for the MODE of the channel. server.cSocket.send("MODE " + m.channel + "\r\n") server.cSocket.send("WHO " + m.channel + "\r\n") else: #Add the user who JOINed to the list of users for ch in server.channels: if ch.cName == m.channel: usr=IRC.user() usr.cNick=m.nick usr.cChannel=ch usr.cTextBuffer = gtk.TextBuffer() ch.cUsers.append(usr) try: cIndex=findIndex(usr,server,ch) except: import traceback;traceback.print_exc() #Call the onUsersChange event for event in IRC.eventFunctions: if event.eventName == "onUserJoin" and event.cServer == server: #Set the users cTreeIter immediately event.aFunc(ch,server,cIndex,usr) #Might couse some random SEGFAULTS!!!!!!!!!!!!!! for event in IRC.eventFunctions: if event.eventName == "onJoinMsg" and event.cServer == server: gobject.idle_add(event.aFunc,m,server,otherStuff)
def noticeResp(server,i,otherStuff): #:[email protected] NOTICE Nyx :test if "NOTICE" in i: m = ResponseParser.parseMsg(i,False) if m is not False: if m.typeMsg == "NOTICE": for event in IRC.eventFunctions: if event.eventName == "onNoticeMsg" and event.cServer == server: gobject.idle_add(event.aFunc,m,server,otherStuff)
def userStuff(server,i):#The user list. global USERS if len(i.split(" ")) > 1: msgCode = i.split(" ")[1] else: return #!--USERS STUFF--!# if ("353" == msgCode): if i.startswith(":"): USERS += "\n" USERS += i if ("366" == msgCode): USERS += "\n" USERS += i m = ResponseParser.parseServer(i) for channel in server.channels: if channel.cName == m[0].channel: #Add the users correctly. pDebug("\033[1;34mParsed server msg 'channel' is " + m[0].channel + "\033[1;m") channel.cUsers = [] for user in ResponseParser.parseUsers(USERS,server,channel): usr = IRC.user() #Get the user mode. userF=user usr.cChannel=channel usr.cTextBuffer=gtk.TextBuffer() while(userF.startswith("*") or userF.startswith("!") or userF.startswith("@") or userF.startswith("%") or userF.startswith("+") or userF.startswith("~") or userF.startswith("&")): usr.cMode += userF[:1] userF=userF[1:] #Get the nickname. usr.cNick = user.replace(usr.cMode,"").replace(" ","") channel.cUsers.append(usr) pDebug("\033[1;32mAdded " + usr.cNick + " to " + channel.cName + " users list " + " with mode " + usr.cMode + "\033[1;m") USERS = "" for event in IRC.eventFunctions: if event.eventName == "onUsersChange" and event.cServer == server: #event.aFunc(channel,server) gobject.idle_add(event.aFunc,channel, server, priority=gobject.PRIORITY_HIGH)
def killResp(server, i, error, otherStuff): #:[email protected] KILL Nyx :DED48385.E7388619.9D7A5108.IP!dom96 (Testing) if "KILL" in i: m = ResponseParser.parseMsg(i,False) pDebug(m);pDebug(m.typeMsg) if m is not False: if m.typeMsg == "KILL": for event in IRC.eventFunctions: if event.eventName == "onKillMsg" and event.cServer == server: gobject.idle_add(event.aFunc,m,server,otherStuff) return "RECONNECT" #Make Nyx reconnect to the server. return error
def privmsgResp(server,i,otherStuff):#the private msg(Normal message) #!--PRIVMSG STUFF START--!# if "PRIVMSG" in i: m = ResponseParser.parseMsg(i,False) if m is not False: #Make sure it's PRIVMSG if m.typeMsg == "PRIVMSG": #pDebug(m.msg) #!--CTCP VERSION--!# if m.msg.startswith("VERSION"): import platform IRCHelper.sendNotice(server,m.nick,"VERSION Nyx 0.1 151309 Copyleft 2009 Mad Dog software - http://sourceforge.net/projects/nyxirc/ - running on " + platform.linux_distribution()[0] + "") #!--CTCP VERSION END--!# #!--CTCP TIME--!# if m.msg.startswith("TIME"): IRCHelper.sendNotice(server,m.nick,"TIME " + strftime("%b %d %H:%M:%S %Z", localtime()) + "") #TIME Aug 02 12:56:09 BST #!--CTCP TIME END--!# #!--CTCP PING--!# if m.msg.startswith("PING"): IRCHelper.sendNotice(server,m.nick,m.msg) #PING 123456789 #!--CTCP PING END--!# #If someone sent YOU a PRIVMSG(i.e to you, not a channel), then make a new 'channel' for that user. if m.channel == server.cNick and m.msg.startswith("") == False: addNewUser=True #:[email protected] PRIVMSG dom96 :pie for ch in server.channels: if ch.cName.lower() == m.nick.lower(): addNewUser=False if addNewUser==True: nChannel = IRC.channel() nChannel.cName = m.nick nChannel.cTextBuffer = gtk.TextBuffer() nChannel.cType = "chanusr" nChannel.cTopic = m.host nChannel.UserListStore = None try: nChannel.cTreeIter = server.listTreeStore.append(server.cTreeIter, \ [m.nick, None, otherStuff.settings.normalTColor, "user"]) except: import traceback; traceback.print_exc() nChannel.cMsgBuffer = [] #This fixes the weird problem with the queue being in the wrong channel. #Add the user who PM'ed you to the Channel list server.channels.append(nChannel) #Call all the onPrivMsg events for event in IRC.eventFunctions: if event.eventName == "onPrivMsg" and event.cServer == server: gobject.idle_add(event.aFunc,m,server,otherStuff)
def cmdSendMsg(server,cChannel,msg): pDebug("\033[1;34mPRIVMSG " + cChannel + " :" + msg + "\\r\\n\033[1;m") server.cSocket.send("PRIVMSG " + cChannel + " :" + msg + "\r\n") cResp = ResponseParser.privMsg() cResp.nick = server.cNick cResp.host = "" cResp.typeMsg = "PRIVMSG" cResp.channel = cChannel cResp.msg = msg #Call all the onOwnPrivMsg events for event in IRC.eventFunctions: if event.eventName == "onOwnPrivMsg" and event.cServer == server: gobject.idle_add(event.aFunc,cResp,server)
def grab_images(page_name): response_page = urllib.request.urlopen(page_name) parser = ResponseParser.ImageParser(strict=False) response_body = response_page.read() parser.feed(response_body.decode('utf-8')) parser.set_image_name() image_links = parser.image_links image_names = parser.image_names counter = 0 for link in image_links: image_bytes = urllib.request.urlopen('http:' + link).read() f = io.open('C:\\Users\\Abdullah AA\\FourChanImages\\' + image_names[counter], 'wb') f.write(image_bytes) counter += 1
def channelModeStuff(server,i,otherStuff): #:irc.archerseven.com 324 Nyx22 #ogame +nt #:irc.archerseven.com 329 Nyx22 #ogame 1253286530 if len(i.split(" ")) > 1: msgCode=i.split(" ")[1] else: return datParsed = ResponseParser.parseServerRegex(i)[0] if msgCode=="324": for ch in server.channels: if ch.cName == datParsed.channel: ch.cMode = datParsed.msg for event in IRC.eventFunctions: if event.eventName == "onChannelModeChange" and event.cServer == server: gobject.idle_add(event.aFunc,datParsed,server,otherStuff) if msgCode=="329": for event in IRC.eventFunctions: if event.eventName == "onChannelModeChange" and event.cServer == server: gobject.idle_add(event.aFunc,datParsed,server,otherStuff)
def quitResp(server,i,otherStuff):#The quit message #!--QUIT MSG--!# if "QUIT" in i: m = ResponseParser.parseMsg(i,False) if m is not False: #Make sure it's a QUIT msg. #:[email protected] KILL gnome|nyx :ikey!admin.ikey.dynalias.com!Dredd (die w***e) if m.typeMsg == "QUIT" or "KILL": for event in IRC.eventFunctions: if event.eventName == "onQuitMsg" and event.cServer == server: gobject.idle_add(event.aFunc,m,server,otherStuff) #Delete the user from the list of users. for ch in server.channels: for usr in ch.cUsers: if usr.cNick.lower()==m.nick.lower(): cTreeIter = usr.cTreeIter #The user is removed from the userlist in the onUserRemove event #Call the onUserRemove event for event in IRC.eventFunctions: if event.eventName == "onUserRemove" and event.cServer == server: gobject.idle_add(event.aFunc,ch,server,cTreeIter,usr)
def partResp(server,i,otherStuff):#The part message #!--PART MSG--!# if "PART" in i: m = ResponseParser.parseMsg(i,False) if m is not False: #Make sure it's a PART msg. if m.typeMsg == "PART": for event in IRC.eventFunctions: if event.eventName == "onPartMsg" and event.cServer == server: gobject.idle_add(event.aFunc,m,server,otherStuff) if m.nick.lower() != server.cNick.lower(): #Delete the user from the list of users. for ch in server.channels: if ch.cName.lower() == m.channel.lower(): for usr in ch.cUsers: if usr.cNick.lower()==m.nick.lower(): cTreeIter = usr.cTreeIter #The TreeIter in the TreeStore to remove. ch.cUsers.remove(usr) #Call the onUserRemove event, which will remove the user from the TreeStore for event in IRC.eventFunctions: if event.eventName == "onUserRemove" and event.cServer == server: gobject.idle_add(event.aFunc,ch,server,cTreeIter,None)
def modeResp(server, i, otherStuff): #:[email protected] MODE ## +o Nyx1 if "MODE" in i: m=ResponseParser.parseMode(i) if m is not False: if m.typeMsg == "MODE": for event in IRC.eventFunctions: if event.eventName == "onModeChange" and event.cServer == server: gobject.idle_add(event.aFunc,m,server,otherStuff) try: #Check if it's a users mode being changed if len(m.msg.split()) >= 2: nM = mLetters(m.msg.split()[0]) pDebug("Mode(Channel format)=" + nM) #This is the 'unfiltered' list of users who's mode got changed #It's taken from the msg received usersWhoModeChanged=m.msg.replace(m.msg.split()[0] + " ","").split(" ") #This is the list of 'filtered'(if there is more then one, of the same nick #then it's just one in this list...), this is added to in the following code. usrModeChangedFiltered = [] #Loop through each mode(+qoa for example(Except the + or -)) for i in range(0, len(m.msg.split()[0][1:])): #Find the channel this mode change happened on. for ch in server.channels: if ch.cName.lower() == m.channel.lower(): #Find the user the mode was given/taken to/from for usr in ch.cUsers: if usr.cNick.lower() == usersWhoModeChanged[i].lower(): #Set the users mode cMode = mLetters(m.msg.split()[0][1:][i]) #The mode, converted into 'channel mode'(i.e what NAMES returns) if m.msg.split()[0][:1] == "-": pDebug(usr.cNick + ".cMode = " + usr.cMode) usr.cMode = usr.cMode.replace(cMode,"") pDebug(usr.cNick + ".cMode = " + usr.cMode) else: usr.cMode += cMode #Check if 'usrModeChangedFiltered' contains this user. contains = False for u in usrModeChangedFiltered: if u[0].cNick.lower() == usr.cNick.lower(): contains = True if contains == False: usrModeChangedFiltered.append([usr, ch]) for i in usrModeChangedFiltered: cIndex = findIndex(i[0], server, i[1]) #i[0] = user, i[1] = channel for event in IRC.eventFunctions: if event.eventName == "onUserOrderUpdate" and event.cServer == server: #event.aFunc(ch,server,cIndex,usr)#Might couse some random SEGFAULTS!!!!!!!!!!!!!! gobject.idle_add(event.aFunc, i[1], server, cIndex, i[0], priority=gobject.PRIORITY_LOW) #If it's not a user's mode being changed...It's most likely a channels mode else: for ch in server.channels: if ch.cName == m.channel: #If the msg contains a -(Minus) then remove the mode from this channels cMode if m.msg.startswith("-"): ch.cMode = ch.cMode.replace(m.msg.replace("-",""),"") #If the msg has a +(plus) then append the mode to this channels cMode else: ch.cMode += m.msg.replace("+","") except: traceback.print_exc()
if (len(vars(args)) == 0): parser.print_help() sys.exit() net = True try: ip = args.ip except: net = False # 'net' command options if (net): # Started selecting arguments if (args.config): res = TC_B.getConfig(args.ip[0], port=args.port, CH=args.CH) ResponseParser.parseSuccess(res) if (args.opendoor): res = TC_B.openDoor(args.ip[0], port=args.port, CH=args.CH) ResponseParser.parseSuccess(res) if (args.date): res = TC_B.getDateOfDevice(args.ip[0], port=args.port, CH=args.CH) ResponseParser.parseSuccess(res) if (args.network): res = TC_B.getNetwork(args.ip[0], port=args.port, CH=args.CH) ResponseParser.parseSuccess(res) if (args.userrecords): res = TC_B.getUserRecords(args.ip[0], port=args.port, CH=args.CH)