Python IndexError: list index out of range

0

I downloaded this Python code here:

# -*- coding: utf-8 -*-
from sys import exit
from json import loads
from Tkinter import *
from time import sleep
from math import floor
from random import randint
from itertools import izip
from urllib2 import urlopen
from threading import Thread
from os import system, remove
from xml.etree import ElementTree
from socket import socket, AF_INET, SOCK_STREAM, SOL_TCP
from socks import socksocket, setdefaultproxy, PROXY_TYPE_HTTP, 
PROXY_TYPE_SOCKS5

system('title Kondra\'s xat raid')

globals()['Threading'] = open('./_inc/Threading.txt','r').read()

class Raider:
    def __init__(self, Chat, Name, Avatar, Homepage, Message, Target, Type, Proxy, ID):
        '''
        if Name == '': self.Name = '[Kondra Raid] chubchub (1322212120)'
        else: self.Name = Name
        '''

        self.Chat, self.Name, self.Avatar, self.Homepage, self.Message, self.Target, self.Type = Chat, Name, Avatar, Homepage, Message, Target, Type
        if Threading == '1': Proxy = Proxy.split(':')

        UserID = ID.split('&UserId=')[1].split('&k1')[0]
        UserK1 = ID.split('&k1=')[1].split('&k2')[0]

        self.IP, self.Port = Proxy[0], int(Proxy[1])
        self.ID, self.K1 = UserID, UserK1

        self.Connect()
    def Connect(self):
        try:
            setdefaultproxy(PROXY_TYPE_HTTP, self.IP, self.Port)
            self.Xat = socksocket(AF_INET, SOCK_STREAM, SOL_TCP)

            self.Xat.settimeout(10)
            self.Xat.connect(("fwdelb02-53956973.us-east-1.elb.amazonaws.com", 10000))

            self.Xat.send('<y r="{0}" v="0" u="{1}" />
Exception in thread Thread-1:
Traceback (most recent call last):
  File "C:\Python27\lib\threading.py", line 801, in __bootstrap_inner
    self.run()
  File "C:\Python27\lib\threading.py", line 754, in run
    self.__target(*self.__args, **self.__kwargs)
  File "C:\Users\guilherme_dorneles\Downloads\RAID BY LUKAS\init.py", line 32, in __init__
    self.IP, self.Port = Proxy[0], int(Proxy[1])
IndexError: list index out of range
'.format(self.Chat,self.ID)) Attributes = ElementTree.fromstring(self.Xat.recv(1024).strip(chr(0))).attrib print Attributes L5 = self.CalculateL5(Attributes['p'],Attributes['i']) self.Xat.send('<j2 cb="'+str(Attributes['c'])+'" Y="2" l5="'+str(L5)+'" l4="'+str(randint(1000,5000))+'" l3="'+str(randint(1000,5000))+'" l2="0" d2="1337" y="'+str(Attributes['i'])+'" k="'+self.K1+'" k3="0" c="'+str(self.Chat)+'" f="0" u="'+str(self.ID)+'" n="'+self.Name+'" a="'+self.Avatar+'" h="'+self.Homepage+'" v="0" />
# -*- coding: utf-8 -*-
from sys import exit
from json import loads
from Tkinter import *
from time import sleep
from math import floor
from random import randint
from itertools import izip
from urllib2 import urlopen
from threading import Thread
from os import system, remove
from xml.etree import ElementTree
from socket import socket, AF_INET, SOCK_STREAM, SOL_TCP
from socks import socksocket, setdefaultproxy, PROXY_TYPE_HTTP, 
PROXY_TYPE_SOCKS5

system('title Kondra\'s xat raid')

globals()['Threading'] = open('./_inc/Threading.txt','r').read()

class Raider:
    def __init__(self, Chat, Name, Avatar, Homepage, Message, Target, Type, Proxy, ID):
        '''
        if Name == '': self.Name = '[Kondra Raid] chubchub (1322212120)'
        else: self.Name = Name
        '''

        self.Chat, self.Name, self.Avatar, self.Homepage, self.Message, self.Target, self.Type = Chat, Name, Avatar, Homepage, Message, Target, Type
        if Threading == '1': Proxy = Proxy.split(':')

        UserID = ID.split('&UserId=')[1].split('&k1')[0]
        UserK1 = ID.split('&k1=')[1].split('&k2')[0]

        self.IP, self.Port = Proxy[0], int(Proxy[1])
        self.ID, self.K1 = UserID, UserK1

        self.Connect()
    def Connect(self):
        try:
            setdefaultproxy(PROXY_TYPE_HTTP, self.IP, self.Port)
            self.Xat = socksocket(AF_INET, SOCK_STREAM, SOL_TCP)

            self.Xat.settimeout(10)
            self.Xat.connect(("fwdelb02-53956973.us-east-1.elb.amazonaws.com", 10000))

            self.Xat.send('<y r="{0}" v="0" u="{1}" />
Exception in thread Thread-1:
Traceback (most recent call last):
  File "C:\Python27\lib\threading.py", line 801, in __bootstrap_inner
    self.run()
  File "C:\Python27\lib\threading.py", line 754, in run
    self.__target(*self.__args, **self.__kwargs)
  File "C:\Users\guilherme_dorneles\Downloads\RAID BY LUKAS\init.py", line 32, in __init__
    self.IP, self.Port = Proxy[0], int(Proxy[1])
IndexError: list index out of range
'.format(self.Chat,self.ID)) Attributes = ElementTree.fromstring(self.Xat.recv(1024).strip(chr(0))).attrib print Attributes L5 = self.CalculateL5(Attributes['p'],Attributes['i']) self.Xat.send('<j2 cb="'+str(Attributes['c'])+'" Y="2" l5="'+str(L5)+'" l4="'+str(randint(1000,5000))+'" l3="'+str(randint(1000,5000))+'" l2="0" d2="1337" y="'+str(Attributes['i'])+'" k="'+self.K1+'" k3="0" c="'+str(self.Chat)+'" f="0" u="'+str(self.ID)+'" n="'+self.Name+'" a="'+self.Avatar+'" h="'+self.Homepage+'" v="0" />%pre%') Data = self.Xat.recv(4096) print Data if '<c' in Data: self.Connect() if '<m t="Limit: ' in Data: sleep(5) if '<logout' in Data or '<dup' in Data: self.Connect() while self.Xat: print Data if self.Type == 'Main': self.Xat.send('<m u="'+self.ID+'" t="'+str(self.Message)+'" />%pre%') elif self.Type == 'PC': self.Xat.send('<z u="'+self.ID+'" t="'+str(self.Message)+'" s="2" d="'+self.Target+'" />%pre%') elif self.Type == 'PM': self.Xat.send('<z u="'+self.ID+'" t="'+str(self.Message)+'" d="'+self.Target+'" />%pre%') elif self.Type == 'Both': pmORpc = randint(1,2) if pmORpc == 1: self.Xat.send('<z u="'+self.ID+'" t="'+str(self.Message)+'" d="'+self.Target+'" />%pre%') else: self.Xat.send('<z u="'+self.ID+'" t="'+str(self.Message)+'" s="2" d="'+self.Target+'" />%pre%') if len(self.Message) < 5: sleep(1) else: sleep(3) except Exception, e: try: self.Connect() except: pass def CalculateL5(self, P, I): Data = open('./_inc/' + P + '.l5','r') Json = {} I = int(I) % 10000 One, Two = I % 100, int(floor(I / 100)) for x in Data: Three, Four = x.strip().split(':') Json[Three] = Four Data.close() return Json[str(One)+','+str(Two)] class Gui: def __init__(self): self.Window = Tk() self.Window.geometry("400x300") self.Window.wm_title("Xat Raid - [Made by: Kondra]") self.Window.configure(background='#C65D64') CLabel = Label(self.Window, text="Chat:", font=("Helvetica", 10)) CLabel.configure(foreground='#FFFFFF',background='#C65D64') CLabel.place(x=85, y=273) self.Chat = Text(self.Window, height = 1, width = 10) self.Chat.configure(foreground='#FFFFFF',background='#C65D64') self.Chat.place(x=125, y=273) Start = Button(self.Window, text="Start Raid", padx = 10, pady = 4, command = self.Start) Start.configure(foreground='#FFFFFF',background='#C65D64') Stop = Button(self.Window, text="Stop Raid", padx = 10, pady = 4, command = self.Stop) Stop.configure(foreground='#FFFFFF',background='#C65D64') ProxyScrape = Button(self.Window, text="Get Proxies", padx = 10, pady = 4, command = self.DoProxies) ProxyScrape.configure(foreground='#FFFFFF',background='#C65D64') ProxyScrape.pack() ProxyScrape.place(x=220, y=265) Start.pack() Start.place(x=5, y=265) Stop.pack() Stop.place(x=315, y=265) MLabel = Label(self.Window, text="Message (to spam):", font=("Helvetica", 10)) MLabel.configure(foreground='#FFFFFF',background='#C65D64') MLabel.place(x=150, y=5) self.Message = Text(self.Window, height = 1, width = 14) self.Message.configure(foreground='#FFFFFF',background='#C65D64') self.Message.place(x=275, y=5) TLabel = Label(self.Window, text="Target ID (for pc/pm raiding):", font=("Helvetica", 10)) TLabel.configure(foreground='#FFFFFF',background='#C65D64') TLabel.place(x=5, y=240) self.Target = Text(self.Window, height = 1, width = 11) self.Target.configure(foreground='#FFFFFF',background='#C65D64') self.Target.place(x=175, y=240) RLabel = Label(self.Window, text="Raid Type (1 = Main, 2 = PC, 3 = PM, 4 = Both):", font=("Helvetica", 10)) RLabel.configure(foreground='#FFFFFF',background='#C65D64') RLabel.place(x=5, y=215) self.Type = Text(self.Window, height = 1, width = 3) self.Type.configure(foreground='#FFFFFF',background='#C65D64') self.Type.place(x=295, y=215) NLabel = Label(self.Window, text="Name:", font=("Helvetica", 10)) NLabel.configure(foreground='#FFFFFF',background='#C65D64') NLabel.place(x=5, y=5) ALabel = Label(self.Window, text="Avatar:", font=("Helvetica", 10)) ALabel.configure(foreground='#FFFFFF',background='#C65D64') ALabel.place(x=5, y=35) HLabel = Label(self.Window, text="Homepage:", font=("Helvetica", 10)) HLabel.configure(foreground='#FFFFFF',background='#C65D64') HLabel.place(x=5, y=65) self.Name = Text(self.Window, height = 0.8, width = 10) self.Name.configure(foreground='#FFFFFF',background='#C65D64') self.Name.place(x=55, y=5) self.Avatar = Text(self.Window, height = 0.8, width = 10) self.Avatar.configure(foreground='#FFFFFF',background='#C65D64') self.Avatar.place(x=55, y=35) self.Homepage = Text(self.Window, height = 0.8, width = 7) self.Homepage.configure(foreground='#FFFFFF',background='#C65D64') self.Homepage.place(x=79, y=65) mainloop() def DoProxies(self): try: remove("./_inc/proxies.txt") except: pass print '##################' print '#Scraping Proxies#' print '##################' Link = urlopen('http://sslproxies24.blogspot.com/').read() Link = self.getBetween(Link,"<a href='http://sslproxies24.blogspot.com/2017/","'>") Link = urlopen("http://sslproxies24.blogspot.com/2017/" + Link).read() Link = self.getBetween(Link,'<span style="color: #00cc00;">','</span>') Proxies = open("./_inc/proxies.txt","a") if Link in open("./_inc/proxies.txt","r").read(): pass else: Proxies.write(Link) Proxies.close() print '###########################' print '#Finished Scraping Proxies#' print '###########################\n\n' print '*******************' print '*Filtering Proxies*' print '*******************' sleep(2) IDs = [i.strip() for i in open('./_inc/ids.txt', 'r')] Proxies = [i.strip() for i in open('./_inc/proxies.txt', 'r')] for (x,y) in izip(Proxies,IDs): try: x = ''.join(x) z = Thread(target=self.Filter,args=(x,y)) z.daemon = True z.start() except: pass def Filter(self,Proxy,Blah): try: P = ''.join(Proxy) Proxy = Proxy.split(':') setdefaultproxy(PROXY_TYPE_HTTP, Proxy[0], int(Proxy[1])) xSock = socksocket(AF_INET, SOCK_STREAM, SOL_TCP) xSock.settimeout(5) xSock.connect(("fwdelb02-53956973.us-east-1.elb.amazonaws.com", 10003)) xSock.send('<y r="1" />%pre%') Data = xSock.recv(1024) if 'k=' in Data: print 'Proxy filtered.' pTxt = open('./_inc/filtered.txt','a') pTxt.write(str(P) + '\n') except: pass def getBetween(self,strSource, strStart,strEnd): start = strSource.find(strStart) + len(strStart) end = strSource.find(strEnd,start) return strSource[start:end] def Stop(self): exit() def Start(self): Chat = urlopen("http://xat.com/web_gear/chat/roomid.php?d=" + self.Chat.get("1.0", "end-1c")).read() Chat = loads(Chat)['id'] print Chat Name = self.Name.get("1.0", "end-1c") Avatar = self.Avatar.get("1.0", "end-1c") Homepage = self.Homepage.get("1.0", "end-1c") Message = self.Message.get("1.0", "end-1c") Target = self.Target.get("1.0", "end-1c") if Message == '': Message = ' ' Type = self.Type.get("1.0", "end-1c") if Type == '': Type = 'Main' if Type == '1': Type = 'Main' elif Type == '2': Type = 'PC' elif Type == '3': Type = 'PM' elif Type == '4': Type = 'Both' Proxies = open('./_inc/filtered.txt', 'r').read() Proxies = Proxies.split('\n') IDs = open('./_inc/ids.txt', 'r').read() IDs = IDs.split('\n') if Threading == '1': ActiveThreads = [] [ActiveThreads.append(Thread(target = Raider, args = [Chat, Name, Avatar, Homepage, Message, Target, Type, Proxy, ID])) for Proxy, ID in zip(Proxies, IDs)] for Th in ActiveThreads: Th.daemon = True try: Th.start() except: pass elif Threading == '2': for (Proxy,ID) in zip(Proxies,IDs): Proxy = Proxy.split(':') Raid = Thread(target=Raider,args=(Chat, Name, Avatar, Homepage, Message, Target, Type, Proxy,ID)) Raid.daemon = True try: Raid.start() except: pass Gui()
') Data = self.Xat.recv(4096) print Data if '<c' in Data: self.Connect() if '<m t="Limit: ' in Data: sleep(5) if '<logout' in Data or '<dup' in Data: self.Connect() while self.Xat: print Data if self.Type == 'Main': self.Xat.send('<m u="'+self.ID+'" t="'+str(self.Message)+'" />%pre%') elif self.Type == 'PC': self.Xat.send('<z u="'+self.ID+'" t="'+str(self.Message)+'" s="2" d="'+self.Target+'" />%pre%') elif self.Type == 'PM': self.Xat.send('<z u="'+self.ID+'" t="'+str(self.Message)+'" d="'+self.Target+'" />%pre%') elif self.Type == 'Both': pmORpc = randint(1,2) if pmORpc == 1: self.Xat.send('<z u="'+self.ID+'" t="'+str(self.Message)+'" d="'+self.Target+'" />%pre%') else: self.Xat.send('<z u="'+self.ID+'" t="'+str(self.Message)+'" s="2" d="'+self.Target+'" />%pre%') if len(self.Message) < 5: sleep(1) else: sleep(3) except Exception, e: try: self.Connect() except: pass def CalculateL5(self, P, I): Data = open('./_inc/' + P + '.l5','r') Json = {} I = int(I) % 10000 One, Two = I % 100, int(floor(I / 100)) for x in Data: Three, Four = x.strip().split(':') Json[Three] = Four Data.close() return Json[str(One)+','+str(Two)] class Gui: def __init__(self): self.Window = Tk() self.Window.geometry("400x300") self.Window.wm_title("Xat Raid - [Made by: Kondra]") self.Window.configure(background='#C65D64') CLabel = Label(self.Window, text="Chat:", font=("Helvetica", 10)) CLabel.configure(foreground='#FFFFFF',background='#C65D64') CLabel.place(x=85, y=273) self.Chat = Text(self.Window, height = 1, width = 10) self.Chat.configure(foreground='#FFFFFF',background='#C65D64') self.Chat.place(x=125, y=273) Start = Button(self.Window, text="Start Raid", padx = 10, pady = 4, command = self.Start) Start.configure(foreground='#FFFFFF',background='#C65D64') Stop = Button(self.Window, text="Stop Raid", padx = 10, pady = 4, command = self.Stop) Stop.configure(foreground='#FFFFFF',background='#C65D64') ProxyScrape = Button(self.Window, text="Get Proxies", padx = 10, pady = 4, command = self.DoProxies) ProxyScrape.configure(foreground='#FFFFFF',background='#C65D64') ProxyScrape.pack() ProxyScrape.place(x=220, y=265) Start.pack() Start.place(x=5, y=265) Stop.pack() Stop.place(x=315, y=265) MLabel = Label(self.Window, text="Message (to spam):", font=("Helvetica", 10)) MLabel.configure(foreground='#FFFFFF',background='#C65D64') MLabel.place(x=150, y=5) self.Message = Text(self.Window, height = 1, width = 14) self.Message.configure(foreground='#FFFFFF',background='#C65D64') self.Message.place(x=275, y=5) TLabel = Label(self.Window, text="Target ID (for pc/pm raiding):", font=("Helvetica", 10)) TLabel.configure(foreground='#FFFFFF',background='#C65D64') TLabel.place(x=5, y=240) self.Target = Text(self.Window, height = 1, width = 11) self.Target.configure(foreground='#FFFFFF',background='#C65D64') self.Target.place(x=175, y=240) RLabel = Label(self.Window, text="Raid Type (1 = Main, 2 = PC, 3 = PM, 4 = Both):", font=("Helvetica", 10)) RLabel.configure(foreground='#FFFFFF',background='#C65D64') RLabel.place(x=5, y=215) self.Type = Text(self.Window, height = 1, width = 3) self.Type.configure(foreground='#FFFFFF',background='#C65D64') self.Type.place(x=295, y=215) NLabel = Label(self.Window, text="Name:", font=("Helvetica", 10)) NLabel.configure(foreground='#FFFFFF',background='#C65D64') NLabel.place(x=5, y=5) ALabel = Label(self.Window, text="Avatar:", font=("Helvetica", 10)) ALabel.configure(foreground='#FFFFFF',background='#C65D64') ALabel.place(x=5, y=35) HLabel = Label(self.Window, text="Homepage:", font=("Helvetica", 10)) HLabel.configure(foreground='#FFFFFF',background='#C65D64') HLabel.place(x=5, y=65) self.Name = Text(self.Window, height = 0.8, width = 10) self.Name.configure(foreground='#FFFFFF',background='#C65D64') self.Name.place(x=55, y=5) self.Avatar = Text(self.Window, height = 0.8, width = 10) self.Avatar.configure(foreground='#FFFFFF',background='#C65D64') self.Avatar.place(x=55, y=35) self.Homepage = Text(self.Window, height = 0.8, width = 7) self.Homepage.configure(foreground='#FFFFFF',background='#C65D64') self.Homepage.place(x=79, y=65) mainloop() def DoProxies(self): try: remove("./_inc/proxies.txt") except: pass print '##################' print '#Scraping Proxies#' print '##################' Link = urlopen('http://sslproxies24.blogspot.com/').read() Link = self.getBetween(Link,"<a href='http://sslproxies24.blogspot.com/2017/","'>") Link = urlopen("http://sslproxies24.blogspot.com/2017/" + Link).read() Link = self.getBetween(Link,'<span style="color: #00cc00;">','</span>') Proxies = open("./_inc/proxies.txt","a") if Link in open("./_inc/proxies.txt","r").read(): pass else: Proxies.write(Link) Proxies.close() print '###########################' print '#Finished Scraping Proxies#' print '###########################\n\n' print '*******************' print '*Filtering Proxies*' print '*******************' sleep(2) IDs = [i.strip() for i in open('./_inc/ids.txt', 'r')] Proxies = [i.strip() for i in open('./_inc/proxies.txt', 'r')] for (x,y) in izip(Proxies,IDs): try: x = ''.join(x) z = Thread(target=self.Filter,args=(x,y)) z.daemon = True z.start() except: pass def Filter(self,Proxy,Blah): try: P = ''.join(Proxy) Proxy = Proxy.split(':') setdefaultproxy(PROXY_TYPE_HTTP, Proxy[0], int(Proxy[1])) xSock = socksocket(AF_INET, SOCK_STREAM, SOL_TCP) xSock.settimeout(5) xSock.connect(("fwdelb02-53956973.us-east-1.elb.amazonaws.com", 10003)) xSock.send('<y r="1" />%pre%') Data = xSock.recv(1024) if 'k=' in Data: print 'Proxy filtered.' pTxt = open('./_inc/filtered.txt','a') pTxt.write(str(P) + '\n') except: pass def getBetween(self,strSource, strStart,strEnd): start = strSource.find(strStart) + len(strStart) end = strSource.find(strEnd,start) return strSource[start:end] def Stop(self): exit() def Start(self): Chat = urlopen("http://xat.com/web_gear/chat/roomid.php?d=" + self.Chat.get("1.0", "end-1c")).read() Chat = loads(Chat)['id'] print Chat Name = self.Name.get("1.0", "end-1c") Avatar = self.Avatar.get("1.0", "end-1c") Homepage = self.Homepage.get("1.0", "end-1c") Message = self.Message.get("1.0", "end-1c") Target = self.Target.get("1.0", "end-1c") if Message == '': Message = ' ' Type = self.Type.get("1.0", "end-1c") if Type == '': Type = 'Main' if Type == '1': Type = 'Main' elif Type == '2': Type = 'PC' elif Type == '3': Type = 'PM' elif Type == '4': Type = 'Both' Proxies = open('./_inc/filtered.txt', 'r').read() Proxies = Proxies.split('\n') IDs = open('./_inc/ids.txt', 'r').read() IDs = IDs.split('\n') if Threading == '1': ActiveThreads = [] [ActiveThreads.append(Thread(target = Raider, args = [Chat, Name, Avatar, Homepage, Message, Target, Type, Proxy, ID])) for Proxy, ID in zip(Proxies, IDs)] for Th in ActiveThreads: Th.daemon = True try: Th.start() except: pass elif Threading == '2': for (Proxy,ID) in zip(Proxies,IDs): Proxy = Proxy.split(':') Raid = Thread(target=Raider,args=(Chat, Name, Avatar, Homepage, Message, Target, Type, Proxy,ID)) Raid.daemon = True try: Raid.start() except: pass Gui()

And I get the error:

%pre%

Does anyone who understands python knowingly explain the reason for this error? I would also like to fix it to learn how to program in Python.

    
asked by anonymous 16.08.2018 / 13:55

1 answer

0

By reading it, it looks like the code tries to read from a text file './_inc/filtered.txt' a list of proxies with their ports, separated by : type like this:

 proxy1.com:1234
 algum_outro_proxy.net:3456
 ...

The error is occurring because when you read this file, the program encountered a line without the : sign. The program is not prepared for this, because Proxy.split(':') will return a list with one element only - then when it will try to use that variable, it will give the error "out of range" in>) when you attempt to access Proxy[0] and Proxy[1] , in this line:

self.IP, self.Port = Proxy[0], int(Proxy[1])

To correct, there are many, infinite forms actually. An example: You can add a check to check if the proxy has a port:

Proxy = Proxy.split(':')
if len(Proxy) < 2:
    print('Proxy sem número de porta no arquivo, será pulado! Verifique!')
    continue

The continue there makes it ignore the proxy without port and go to the next, so it will not give more error.

    
16.08.2018 / 20:49