Python to Ruby:如何打开文件,解析数据和多线程?

时间:2021-05-04 20:44:48

I need to translate this into Ruby:

我需要把它翻译成Ruby:

ids = [i.strip() for i in open('ids.txt','r')]
proxies = [i.strip() for i in open('socks.txt','r')]
for (i,j) in izip(ids,proxies):
    i = parseID(i)
    j = j.split(':')
    threading.Thread(target=raider,args=(i,j)).start()

This is just showing you what's happening with it:

这只是告诉你它发生了什么:

def parseID(auser3):
auser3 = auser3.split('&')
userid = auser3[1].split('=')[1]
k1 = auser3[2].split('=')[1]
k2 = auser3[3].split('=')[1]
return [userid,k1,k2]
return l5

def raider(a3,p):
global ip
global port
try:
    socks.setdefaultproxy(socks.PROXY_TYPE_SOCKS4, p[0], int(p[1]))
    socket.test = socks.socksocket
    xat = socket.test(socket.AF_INET, socket.SOCK_STREAM, socket.SOL_TCP)
    xat.connect((ip,int(port)))
    xat.send('<y r="'+str(info[2])+'" />\0')
    bypass = xat.recv(1024)
    print "\nRecv --> "+bypass+"\n"
    rcv = tree.fromstring(bypass.strip("\0"))
    if 'i' not in rcv.attrib:
        raise Exception("YUP")
    import pprint
    pprint.pprint(a3)
    print p[0]+":"+p[1]+"\n\n"
    uid = a3[0]
    k = a3[1]
    Y = getY(rcv.attrib["au"], rcv.attrib["p"].split("_")[0],rcv.attrib["p"].split("_")[1],rcv.attrib["p"].split("_")[2],rcv.attrib["p"].split("_")[3], rcv.attrib["i"])
    j2 = str('<j2 cb="'+rcv.attrib["c"]+'" Y="'+str(Y[0])+'" l5="'+str(Y[1]).strip()+'" l4="583" l3="463" l2="0" q="1" y="'+rcv.attrib['i']+'" k="'+k+'" k3="0" p="0" c="'+str(info[2])+'" f="0" u="'+str(uid)+'" d0="0" n=" " a="0" h="" v="0" />\0')
    xat.send(j2)
    print "\nSend --> "+j2+"\n"
    while 1:
        text = xat.recv(4069)
        if 'logout' in text or 'idle' in text or 'dup' in text:
            raider(a3, p)
        else:
            time.sleep(1)
            xat.send('<m t=" " u="'+uid+'" />\0')
except:
    raider(a3, p)

I made an attempt but it failed:

我做了一次尝试,但失败了:

def raid()
    $proxies = []
    $ids = []
    IO.foreach('ids.txt') do |line| # Foreach id as a line 
        $ids << line #ine.scan(/&Userid=(.*?)&k1=(.*?)&k2=([0-9]+)/i) # parse id
    end
    IO.foreach('socks.txt') do |line|
        $proxies << line
    end
    $test = $ids.zip($proxies)
end

It reads the data from the two files, matches each ID with a Proxy, and sends it to a function.

它从两个文件中读取数据,将每个ID与代理匹配,并将其发送到函数。

1 个解决方案

#1


0  

I'd write it like:

我写的就像:

def raid()
  ids = File.readlines('ids.txt')
  proxies = File.readlines('socks.txt')
  ids.zip(proxies).map{ |a| a.map(&:chomp) }
end

Starting with two files:

从两个文件开始:

  • socks.txt:

    socks.txt:

    127.0.0.1
    127.0.0.2
    
  • ids.txt:

    ids.txt:

    foo
    bar
    

Calling the above method returns:

调用上面的方法返回:

raid() # => [["foo", "127.0.0.1"], ["bar", "127.0.0.2"]]

"...sends it to a function"

“......将其发送给一个函数”

I'm not sure where in your code you tried to call a function, so I can't replicate that.

我不确定你的代码在哪里尝试调用函数,所以我不能复制它。

#1


0  

I'd write it like:

我写的就像:

def raid()
  ids = File.readlines('ids.txt')
  proxies = File.readlines('socks.txt')
  ids.zip(proxies).map{ |a| a.map(&:chomp) }
end

Starting with two files:

从两个文件开始:

  • socks.txt:

    socks.txt:

    127.0.0.1
    127.0.0.2
    
  • ids.txt:

    ids.txt:

    foo
    bar
    

Calling the above method returns:

调用上面的方法返回:

raid() # => [["foo", "127.0.0.1"], ["bar", "127.0.0.2"]]

"...sends it to a function"

“......将其发送给一个函数”

I'm not sure where in your code you tried to call a function, so I can't replicate that.

我不确定你的代码在哪里尝试调用函数,所以我不能复制它。