admin管理员组

文章数量:1552535

[Python] 纯文本查看 复制代码#!/usr/bin/env python

# encoding: utf-8

import socket

from hashlib import sha1

from random import randint

from struct import unpack

from socket import inet_ntoa

from threading import Timer, Thread

from time import sleep

from collections import deque

from bencode import bencode, bdecode

BOOTSTRAP_NODES = (

("router.bittorrent", 6881),

("dht.transmissionbt", 6881),

("router.utorrent", 6881)

)

TID_LENGTH = 2

RE_JOIN_DHT_INTERVAL = 3

TOKEN_LENGTH = 2

def entropy(length):

return "".join(chr(randint(0, 255)) for _ in xrange(length))

def random_id():

h = sha1()

h.update(entropy(20))

return h.digest()

def decode_nodes(nodes):

n = []

length = len(nodes)

if (length % 26) != 0:

return n

for i in range(0, length, 26):

nid = nodes[i:i+20]

ip = inet_ntoa(nodes[i+20:i+24])

port = unpack("!H", nodes[i+24:i+26])[0]

n.append((nid, ip, port))

return n

def timer(t, f):

Timer(t, f).start()

def get_neighbor(target, nid, end=10):

return target[:end]+nid[end:]

本文标签: 磁力大神来个源码搜索网站