def close_port(self): sock = ssocket(AF_INET,SOCK_STREAM) sock.settimeout(2) if sock.connect_ex((self.ip,self.port)) == 0: for process in process_iter(): try: for conn in process.connections(kind='inet'): if self.port == conn.laddr.port: process.send_signal(SIGTERM) process.kill() except: pass if sock.connect_ex((self.ip,self.port)) != 0: return True else: self.logs.error(['errors',{'server':'dns_server','error':'port_open','type':'Port {} still open..'.format(self.ip)}]) return False
def __init__(self, target = address): self.packet = ''.join(mantra_large) self.address = tuple(target) self.sock = ssocket(AF_INET, SOCK_DGRAM) self.sock.bind(self.address)