Last active
December 12, 2019 18:12
-
-
Save Mukundan314/e8670a08eb4ba6c7485cc0892a3f57cc to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import argparse | |
import socket | |
import sys | |
from tqdm import trange | |
def main(argv): | |
parser = argparse.ArgumentParser(description="A port scanner") | |
parser.add_argument("host", type=str) | |
parser.add_argument("-t", "--timeout", type=float, default=0.1) | |
args = parser.parse_args(argv[1:]) | |
open_ports = [] | |
for port in trange(0, 65536): | |
sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM) | |
sock.settimeout(args.timeout) | |
if sock.connect_ex((args.host, port)) == 0: | |
open_ports.append(port) | |
sock.close() | |
print("Open Ports:", *open_ports) | |
if __name__ == "__main__": | |
main(sys.argv) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment