예제 #1
0
파일: wire.py 프로젝트: idrisr/bt-client
def get_msg():
    t = Torrent('../torrent/flagfromserver.torrent')
    t.make_request()

    # make request, get response, handle response
    r = requests.get(t.request)
    rh = ResponseHandler(r)
    rh.get_peer_ip()

    # get handshake
    h = Handshake(t)

    #pick ip and port from peers
    ip = rh.ips[-1][0]
    port = rh.ips[-1][1]

    # socket connection and send data
    s = socket.socket()
    s.connect((ip, port))
    s.sendall(str(h))

    # receive data back and pretty print 
    recv = s.recv(100)
    print 'Handshake received: %s' % (recv.__repr__(), )


    s.sendall(send_interested())
    recv = s.recv(10000)
    prefix, message = message_decode(recv)
    return recv
예제 #2
0
        n = 6
        self.ips = []
        for i in xrange(0, len(bs), n):
            ip = '.'.join([str(b) for b in bs[i:i+n-2]])
            port = bs[i+(n-2)] * 256 + bs[i+(n-1)]
            self.ips.append((ip, port))


    def __repr__(self):
        print_fields = ['_content',
                'ips',
                'peers',
                'status_code',
                'url']

        return '\n'.join(['%s:\t%r' % (field, getattr(self, field), ) for field in print_fields])


if __name__ == '__main__':
    try: 
        filename = sys.argv[1]
    except IndexError:
        filename = '../torrent/flagfromserver.torrent'
        #filename = '../torrent/linuxmint-16-cinnamon-dvd-64bit.torrent'

    t = Torrent(filename)
    t.make_request()
    response = requests.get(t.request)
    response_handler = ResponseHandler(response)
    response_handler.get_peer_ip()