Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #Proxy Genius - by Dberube4
- import urllib.request,tempfile,time
- class proxyGenius():
- def __init__(self,dbgLvl = 0):
- self.dbgLvl = dbgLvl
- if 1: #Headers for the request EVERYTHING IS NEEDED
- self.headers={}
- self.headers['Host']='www.ip-adress.com'
- self.headers['User-Agent']='Mozilla/5.0 (Windows NT 6.1; WOW64; rv:11.0) Gecko/20100101 Firefox/11.0'
- self.headers['Accept']='text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8'
- self.headers['Accept-Language']='fr,fr-fr;q=0.8,en-us;q=0.5,en;q=0.3'
- self.headers['Content-Type']='application/x-www-form-urlencoded;charset=utf-8'
- self.headers['X-Moz']='prefetch'
- self.headers['Accept-Charset']='ISO-8859-1,utf-8;q=0.7,*;q=0.7'
- self.headers['Referer']='http://www.google.com'
- self.headers['Cache-Control']='no-cache, no-cache'
- self.headers['Pragma']='no-cache'
- self.tmpDir = tempfile.gettempdir()+'/'
- self.ip = self.getIp()
- if self.dbgLvl == 1:
- print('Proxy Genius Inited')
- def getIp(self):
- url = urllib.request.urlopen('http://automation.whatismyip.com/n09230945.asp')
- ip = str(url.read(),'utf8')
- if self.dbgLvl == 1:
- print('Public IP:',ip)
- return ip
- def getLatestProxy(self):
- #send a request to the web page
- req = urllib.request.Request('http://www.ip-adress.com/proxy_list/',headers=self.headers)
- text = urllib.request.urlopen(req)
- #save the webpage
- name = self.tmpDir+'tmp.tmp'
- tmp = open(name,'w').write(str(text.read(),'utf8'));
- #This get latest proxy (and related info) off the saved source.
- a = open(name,'r');n = 0
- while n != 250:
- line = a.readline()
- n+= 1
- else:
- proxy = a.readline().replace('<td>','');proxy = proxy.replace('</td>','');proxy = proxy.replace('\n','')
- proxy = proxy.replace(' ','')
- while n != 251:
- line = a.readline()
- n+= 1
- else:
- type = a.readline().replace('<td>','');type = type.replace('</td>','');type = type.replace('\n','')
- type = type.replace(' ','')
- if self.dbgLvl == 1:
- print('Proxy address: ',proxy,' Proxy type: ',type)
- return([proxy,type])
- def listProxies(self,Filter = 'None',Max = 30):
- #Possible Filter: 'None','Anonymous','Transparent','Elite',''
- if Max > 30:
- Max = 30
- temp = {'1':174,'2':210,'3':246,'4':282,'5':318,'6':354,'7':390,'8':426,'9':462,'10':498,'11':534,'12':570,'13':606,'14':642,'15':678,'16':714,'17':750,'18':786,'19':822,
- '20':858,'21':894,'22':930,'23':966,'24':1002,'25':1038,'26':1074,'27':1110,'28':1146,'29':1182,'30':1218}
- proxDict = {}
- #send a request to the web page
- req = urllib.request.Request('http://www.ip-adress.com/proxy_list/',headers=self.headers)
- text = urllib.request.urlopen(req)
- #save the webpage
- name = self.tmpDir+'tmp.tmp'
- tmp = open(name,'w').write(str(text.read(),'utf8'));
- #This get latest proxy (and related info) off the saved source.
- a = open(name,'r');n = 0
- for i in range(1,Max+1):
- number = temp[str(i)]
- while n != number:
- line = a.readline()
- n+= 1
- else:
- proxy = a.readline().replace('<td>','');proxy = proxy.replace('</td>','');proxy = proxy.replace('\n','')
- proxy = proxy.replace(' ','')
- while n != number+1:
- line = a.readline()
- n+= 1
- else:
- type = a.readline().replace('<td>','');type = type.replace('</td>','');type = type.replace('\n','')
- type = type.replace(' ','')
- if self.dbgLvl == 1:
- print('Proxy address: ',proxy,' Proxy type: ',type)
- if Filter == 'None':
- proxDict[str(i)] = [proxy,type]
- elif Filter == 'Anonymous' and type == 'Anonymous':
- proxDict[str(i)] = [proxy,type]
- elif Filter == 'Elite' and type == 'Elite':
- proxDict[str(i)] = [proxy,type]
- elif Filter == 'Transparent' and type == 'Transparent':
- proxDict[str(i)] = [proxy,type]
- if len(proxDict) == 0:
- print('No proxy found.If you are using a filter,set the max to 30')
- return proxDict
- def testProxy(self,proxy):
- if self.dbgLvl == 1:
- print('Testing',proxy,'...')
- try:
- req = urllib.request.Request('http://automation.whatismyip.com/n09230945.asp')
- req.set_proxy(proxy,'http')
- text = urllib.request.urlopen(req)
- ip = str(text.read(),'utf8')
- if ip == self.ip:
- if self.dbgLvl == 1:print('Proxy is not working!')
- return False
- else:
- if self.dbgLvl == 1:print('Proxy is working!')
- return True
- except:
- return False
- if __name__ == '__main__':
- print('''Proxy Genius self execution.\nCommands:\n1: Print latest proxy information.\n2: Print a list of proxies\n3: Get your public ip\n4: Test a proxy\n''')
- genius = proxyGenius(0)
- while 1:
- Input = str(input('Command Number: '))
- try:
- if Input == '1':
- print(genius.getLatestProxy())
- elif Input == '2':
- Filter = input('Select Filter (None,Anonynous,Elite,Transparent): ')
- num = int(input('Select number of proxies to get(30 = Max): '))
- print(genius.listProxies(Filter,num))
- elif Input == '3':
- print(genius.getIp())
- elif Input == '4':
- proxy = input('Enter proxy([Domain]:[Port]): ')
- print(genius.testProxy(proxy))
- else:
- print('This is not a valid input')
- except:
- print('Something went wrong.')
Advertisement
Add Comment
Please, Sign In to add comment