本文整理汇总了Python中action.Action.checkmd5方法的典型用法代码示例。如果您正苦于以下问题:Python Action.checkmd5方法的具体用法?Python Action.checkmd5怎么用?Python Action.checkmd5使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类action.Action
的用法示例。
在下文中一共展示了Action.checkmd5方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: __init__
# 需要导入模块: from action import Action [as 别名]
# 或者: from action.Action import checkmd5 [as 别名]
#.........这里部分代码省略.........
self.address = (self.ip_address, self.port)
self.sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
self.sock.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
self.sock.bind(self.address)
return None
def listen(self):
self.sock.listen(10)
while True:
print 'waiting for a connection'
connection, client_address = self.sock.accept()
try:
print 'connection from', client_address
request = connection.recv(32768)
parse_result = self.parseRequestHeader(request)
print 'parse_result >>>', parse_result
method, command, params = parse_result
if command == "/crack":
print "dealing with a browser client"
connection.send('HTTP/1.1 200 OK\n')
connection.send('Content-Type: text/html; encoding=utf8\n')
#TODO maybe add a time-out header
connection.send('Connection: keep-alive\n')
connection.send('\n') # to separate headers from body
connection.send('<html><body>')
connection.send('<h1>Hello, %s:%i!</h1>' %(client_address))
connection.send('<h2>Requested MD5: %s</h2>' %(params['md5'][0]))
connection.send('\n\n')
if not self.connection:
self.connection = connection
print "created self.connection"
else:
print "Master server is busy atm"
connection.send('<p> This server is already busy with another thread. Try again later.\n')
connection.close()
continue
else:
print "dealing with inside requests"
connection.send("OK")
connection.close()
t = threading.Thread(target=self.handleRequest, args=(parse_result,))
t.start()
except:
print >>sys.stderr, "An error has occured while listening." , sys.exc_info()
return None
def handleRequest(self, query_data):
method, command, params = query_data
print "inside handleRequest() thread version"
if method == "GET":
# SLAVE receives from MASTER
if command == "/resource":
self.handle.resource(self, params)
# MASTER receives from USER
if command == "/crack":
self.handle.crack(self, params)
if method == "POST":
# MASTER receives from SLAVE
if command == "/resourcereply":
self.handle.resourcereply(self, params)
# SLAVE receives from MASTER
if command == "/checkmd5":
self.handle.checkmd5(self, params)
# MASTER receives from SLAVE
if command == "/answermd5":
self.handle.answermd5(self, params)
def checkResourceAvailable(self):
return self.resource['available']
def getResourceAmount(self):
return self.resource['amount']
def sendResourceReply(self, sendip, sendport, task_id, resource):
## resourcereply:[ip, port, id, resource=100]
print "inside sendResourceReply()"
ip_address = self.ip_address
port = self.port
# resource = {available: True/False, amount: 100(const)}
url = "http://%s:%s/resourcereply" %(sendip, sendport)
data = json.dumps({"ip":ip_address, "port":port, "id":task_id, "resource":resource})
print "url:", url
print "data:", data
print "next I'm going to send the resourceReply"
try:
req = urllib2.Request(url, data, {'Content-Type': 'application/json'})
response_stream = urllib2.urlopen(req)
response_stream.close()
except urllib2.HTTPError, err:
print "HTTPError", err.code
except urllib2.URLError, err:
print "URLError", err.reason