Skip to content

Commit

Permalink
Add knock python software
Browse files Browse the repository at this point in the history
  • Loading branch information
pdostal committed Dec 1, 2023
1 parent 3b347c7 commit 2347bd7
Showing 1 changed file with 39 additions and 0 deletions.
39 changes: 39 additions & 0 deletions knock
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
#!/usr/bin/python3
## From: https://gist.github.com/rootsploit/db83a6975c7c1337106950b81b6df733/

import socket
import itertools
import sys
import time
import argparse

class Knockit(object):
def __init__(self, args: list):
self._parse_args(args)

def _parse_args(self, args: list):
parser = argparse.ArgumentParser()
parser.add_argument('-d', '--delay', type=int, default=200,
help='Delay between each knock. Default is 200 ms.')
parser.add_argument('host', help='Hostname or IP address of the host.')
parser.add_argument('ports', type=int, help='Port(s) to knock on', nargs='+')

args = parser.parse_args(args)
self.delay = args.delay / 1000
self.ports = args.ports
self.host= args.host


def knockit(self):
self.ports = list(map(int, self.ports))

for port in self.ports:
print("[+] Knocking on port %s:%s" % (self.host,port))
sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
sock.settimeout(self.delay)
sock.connect_ex((self.host, port))
sock.close()


if __name__ == '__main__':
Knockit(sys.argv[1:]).knockit()

0 comments on commit 2347bd7

Please sign in to comment.