sockets - Silence Errno[32] Broken pipe can't solve python -


i've been working on honeypot vps, hosts scan vps give me following output

unhandled exception in thread started <function clientthread @ 0x7fe454975050> traceback (most recent call last):   file "server.py", line 56, in clientthread     conn.sendall(reply)   file "/usr/lib/python2.7/socket.py", line 228, in meth     return getattr(self._sock,name)(*args) socket.error: [errno 32] broken pipe 

here python code,

import socket import os import time import sys thread import * datetime import datetime  host = sys.argv[1] port = int(sys.argv[2])  w  = '\033[0m'  # white (normal) r  = '\033[31m' # red g  = '\033[32m' # green  if os.name == 'posix':     cls = 'clear' elif os.name == 'nt':     sys.exit("this meant linux machines only!")  s = socket.socket(socket.af_inet, socket.sock_stream) os.system(cls) print r+'-'+g * 18 print r+'|'+g+' socket started '+r+'|' print r+'-'+g * 18 time.sleep(1)  try:     s.bind((host, port)) except socket.error msg:     print 'bind failed. error code : ' + str(msg[0]) + ' message ' + msg[1]     sys.exit()  os.system(cls) print r+'-'+g * 24 print r+'|'+g+' socket bind complete '+r+'|' print r+'-'+g * 24 time.sleep(1)  os.system(cls) s.listen(10) print r+'-'+g * 24 print r+'|'+g+' socket listening '+r+'|' print r+'-'+g * 24 print w+'below show listed clients connect' time.sleep(1)  def clientthread(conn):     conn.send('connected\n')      while true:          data = conn.recv(512)         reply = 'ok... \n' + data * 500         if not data:              break          conn.sendall(reply)      conn.close()  try:     while 1:         conn, addr = s.accept()         print 'connected ' + addr[0] + ':' + str(addr[1])         honeypot = open("honeypot.log","a")         honeypot.write("\r\nlogged: " + addr[0] + ":" + str(addr[1]))         honeypot.truncate()         honeypot.close()          start_new_thread(clientthread ,(conn,))  except socket.error:     pass  s.close() 

i've tried other posts via stackoverflow, , other sites. still cannot find understandable way of silencing socket error. i've tried using exceptions, still won't silence it..


Comments

Popular posts from this blog

php - Vagrant up error - Uncaught Reflection Exception: Class DOMDocument does not exist -

vue.js - Create hooks for automated testing -

Add new key value to json node in java -