您现在的位置: Tracy‘Blog > 博客 > Python > 正文
pydial.py V2.0

 

   老早写的了,权当记录下,以防下次kali又奔溃了。然后·~~没地儿哭。

    python实现的,Linux下自动处理账号,然后,自动循环随机拨号。

    直接放源码吧,代码写的丑,还请大牛勿喷:

 

 

 

 

###########################################################################
#   This script is to handle the pppoe.log, and then dial with the available account.
#   It can automatic do the loop dial with those account which you have got until you can surf the Net.
#   Author:Tracy
#   E_mail:purpleroc@126.com
#   Url:www.purpleroc.com
###########################################################################
import pickle
import os
import random
import re
import time
import sys


class switch(object):
#################################################################
#This class is to implement the struct of swtich```case
#################################################################
    def __init__(self, value):
        self.value = value
        self.fall = False
    def __iter__(self):
        """Return the match method once, then stop"""
        yield self.match
        raise StopIteration
    def match(self, *args):
        """Indicate whether or not to enter a case suite"""
        if self.fall or not args:
            return True
        elif self.value in args: # changed for v1.5, see below
            self.fall = True
            return True
        else:
            return False


#####################################################################
#Handle the account first
#####################################################################
def handle_first():
	try:
		os.system('cat /var/log/pppoe.log | grep password | grep -v pppd >> /root/pppoe/tmp.log && rm -f /var/log/pppoe.log')
		os.system('cat /root/pppoe/tmp.log >> /root/pppoe/credit.log && rm /root/pppoe/tmp.log')
		with open('/root/pppoe/credit.log') as tem:
			temp = tem.read()
		e_line=temp.splitlines()
		credit=[]
	#Frist handle
	#username save to [][1],and the password save to [][2]
		for e_item in e_line:
			credit.append(re.split('user=|password=',e_item))
	#Get the username and password
	#username save to [][0],and the password save to [][1]
		for i in range (0,len(credit)):
			#print i,len(credit)
			credit[i][1]=credit[i][1][13:len(credit[i][1])-2]
			credit[i][2]=credit[i][2][1:len(credit[i][2])-2]
			del(credit[i][0])
		fin_cre=[]

	#Secend handle get the username and password exactly
		for i in range (0,len(credit)):
			for case in switch(len(credit[i][0])):
				if case(0):
					del(credit[i][0])
					del(credit[i][0])
					break
				if case(5):
					del(credit[i][0])
					del(credit[i][0])
					break
				if case(12):
					credit[i][0]=credit[i][0][1:]
					break
				if case(18):
					credit[i][0]=credit[i][0][1:]
					break
				if case(14):
					credit[i][0]=credit[i][0][1:]
					break
				if case(16):
					credit[i][0]=credit[i][0][1:]
					break
	#       print fin_cre[i]
		fin_cre1=[]
	#Remove the mul user
		for x in credit:
			if x not in fin_cre1:
				fin_cre1.append(x)
	#Then the username and passsword has handled,and saved it
		with open('/root/pppoe/credit.dat','wb') as savedata:
			pickle.dump(fin_cre1,savedata)
		file = open('/root/pppoe/credit.txt','w')
		file.writelines('%s\n' % item for item in fin_cre1)  
		file.close

	except IOError as err:
		print("Read File Error:"+str(err))
	finally:
		if 'user_data' in locals():
			user_data.close()
		if 'pass_data' in locals():
			pass_data.close()
		if 'eth_data' in locals():
			eth_data.close()
		if 'resdata' in locals():
			resdata.close()

def dial():
#####################################################################
#           Dial   Start
#####################################################################
    with open('/root/pppoe/credit.dat','rb')as resdata:
        credit=pickle.load(resdata)
    i=random.randrange(0,len(credit))
    while True:
        if i==len(credit):
            i=random.randrange(0,len(credit))
        with open('/usr/local/openkeeper/config/user','w')as user_data:
            user_data.write(credit[i][0])
        with open('/usr/local/openkeeper/config/pass','w')as pass_data:
            pass_data.write(credit[i][1])
        if len(sys.argv)==2:
            with open('/usr/local/openkeeper/config/eth','w')as eth_data:
                eth_data.write(sys.argv[1])
        if os.system('test -n "`ifconfig|grep ppp`"') == 0:
            print "You have already on the Internet!!!"
            break
        else:
            print "Try to use the account: "+credit[i][0]+" to surfer the Internet"
            result=os.popen('okok').read()
        print result
        i=i+1	
        if not result.find("Connected")==-1:
            break
        print "\nUse the Next account~~!"'\n'
        time.sleep(3)

if __name__ == '__main__':
	if os.path.exists('/var/log/pppoe.log'):
		handle_first()
	dial()
"""
"""



——Tracy_梓朋

2014年6月20日16:12:13

发表评论(0)
姓名 *
电子邮件
QQ
评论内容 *
验证码 *图片看不清?点击重新得到验证码请输入图片后链接字符‘a’