diff --git a/checkmyip.py b/checkmyip.py old mode 100644 new mode 100755 index 0733293..f5b8f88 --- a/checkmyip.py +++ b/checkmyip.py @@ -160,11 +160,11 @@ def telnet_talker(client, valdict): log(j2format(j2log, valdict)) client.send(j2format(j2send, valdict)) # echo client.close() - #quit() def ssh_talker(client, valdict): valdict.update({"proto": "ssh"}) + log(j2format(j2log, valdict)) t = paramiko.Transport(client, gss_kex=True) t.set_gss_host(socket.getfqdn("")) t.load_server_moduli() @@ -174,82 +174,37 @@ def ssh_talker(client, valdict): chan = t.accept(20) if chan: server.event.wait(10) - #chan.send(j2format(j2log, valdict)) - log(j2format(j2log, valdict)) chan.send('%s' % j2format(j2send, valdict)) chan.makefile('rU').readline().strip('\r\n') - chan.close() - #quit() + chan.close() + client.close() def http_talker(client, valdict): - def recv_all(sock): - prev_timeout = sock.gettimeout() - try: - sock.settimeout(0.01) - rdata = [] - while True: - try: - rdata.append(sock.recv(MAX_PACKET)) - except socket.timeout: - return ''.join(rdata) - finally: - sock.settimeout(prev_timeout) - def normalize_line_endings(s): - return ''.join((line + '\n') for line in s.splitlines()) - while True: - # headers and body are divided with \n\n (or \r\n\r\n - that's why we - # normalize endings). In real application usage, you should handle - # all variations of line endings not to screw request body - request = normalize_line_endings(recv_all(client)) # hack again - request_head, request_body = request.split('\n\n', 1) - # first line is request headline, and others are headers - request_head = request_head.splitlines() - request_headline = request_head[0] - # headers have their name up to first ': '. In real world uses, they - # could duplicate, and dict drops duplicates by default, so - # be aware of this. - request_headers = dict(x.split(': ', 1) for x in request_head[1:]) - # headline has form of "POST /can/i/haz/requests HTTP/1.0" - request_method, request_uri, request_proto = request_headline.split(' ', 3) - response_body = [ - '
This page is in location %(request_uri)r, was requested ' % locals(), - 'using %(request_method)r, and with %(request_proto)r.
' % locals(), - 'Request body is %(request_body)r
' % locals(), - 'Actual set of headers received:
', - '