Gabriel87 Posted July 24, 2011 Report Posted July 24, 2011 #!/usr/bin/env python#Name: portblock.py#Author: s3my0n#Email: RuSH4ck3R[at]gmail[dot]comfrom socket import *import sysdef Main(ADDR, MAXRESP): try: server = socket(AF_INET, SOCK_STREAM) server.bind(ADDR) server.listen(5) # 5 is maximum connection at a time except BaseException, e: print '\n [-]%s' % e sys.exit() notdone = True count = 0 #will increase by one on response while notdone: try: print '\n[+]Wating for connection' client, caddr = server.accept() print '\n Connection from: ', caddr client.send('\n\aAccess Denied on port: %d\n' % (port)) #beep xD client.close() count += 1 if count == MAXRESP: break #if you close the server here, you will get an error except KeyboardInterrupt: print '\n [-]Aborted' #will only exit when data has been recieved sys.exit() except BaseException, e: print '\n [-]%s' % e sys.exit(1) server.close() sys.exit()if __name__=='__main__': if len(sys.argv) not in [3, 4]: print '\n\t#############' print '\t# By s3my0n #' print '\t#############' print '\n\tUsage: portblock.py [host IP] [port] [maximum responses]' print '\t portblock.py [port] [maximum responses]' print '\n\tDefault host IP address is localhost' sys.exit() if len(sys.argv) == 4: host = sys.argv[1] #user host IP address (p, m) = (2, 3) #just a workaround (hack ;-]) else: host = '127.0.0.1' #default host IP address (p, m) = (1, 2) try: port = int(sys.argv[p]) #port number maxresp = int(sys.argv[m]) #maximum responses except ValueError: print '\n [-]Number needed for port and max responses' sys.exit() if port not in range(1, 65536): print '\n [-]Invalid port number' sys.exit() addr = (host, port) #address for binding Main(addr, maxresp) # initializing the server Quote