PORTSCANNING-IN-PYTHON - A python threaded portscanner to scan websites and ipaddresses

Overview

PORTSCANNING-IN-PYTHON

This is a python threaded portscanner to scan websites and ipaddresses.

To run the script:

git clone the file.

chmod +x portscanner.py

python portscanner.py

PORTSCANNING IN PYTHON 1 PORTSCANNING IN PYTHON Portscanning refers to locating “listening” TCP or UDP ports and obtaining sufficient information about the device from the ports. Port scanning involves the transmission of TCP segments or UDP datagrams to interesting port numbers at a given IP address. Our goal when port scanning is to answer three questions regarding the server;

  1. What ports are open?
  2. What services are running on these ports?
  3. What versions of those services are running? PYTHON SCRIPT 💡 You need basic python skills and an understanding of threading, the Queue module, and the socket module to understand the script better. First things first, Import the modules

from queue import Queue import socket import time import threading import pyfiglet import os from datetime import datetime

The main module is the socket module. This module provides access to the BSD socket interface.

clear=lambda : os.system('clear') clear()

PORTSCANNING IN PYTHON 2 Use os.system(’cls’) for windows. This will blank the screen once you run the script.

banner=pyfiglet.figlet_format("MINUTEBOSS") print (banner)

This creates a banner with the name MINUTEBOSS, feel free to change it and add fonts and styles of your liking.

print("1.Scan ipaddress.\n") print("2.Scan website.\n") choice=input("Enter option:") if choice=='1': target=input("Enter ipaddress to scan:") if choice=='2': website=input("Enter hostname to scan:") target=socket.gethostbyname(website)

Get the target ip or website name to scan. socket.gethostbyname() gets the ip of a website.

print ("Scanning target:" + target) print ("Scanning started at:"+str(datetime.now())) print ("-" * 50) q = Queue() open_ports = []

The first 3 print statements display information about the target and starting time. We use q to work with the Queue module. We define a list (open_ports) to store the list of open ports.

def portscan(port): try: sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM) sock.connect((target, port)) return True except: return False

PORTSCANNING IN PYTHON 3 The function portscan tries to connect to the given ports which we will introduce later. A pair (target, port) is used for the AF_INET address family, where the target is a string representing an IPv4 address like '100.50.200.5' , and port is an integer.

def get_ports(): for port in range(1,65535): q.put(port)

We queue the ports using this function. We also define all ports in this function. You can change the range to scan specified ports of your liking.

def portguy(): while not q.empty(): port = q.get() if portscan(port): print("Port {} is open!".format(port)) open_ports.append(port) else: pass

This function checks whether the queue is empty, if not an if statement checks the return value of the portscan function for different given ports. This is easily managed using the Queue module. Open ports are appended on the open_ports list. For closed ports nothing is done.

def run_scanner(threads): get_ports() thread_list = [] for t in range(threads): thread = threading.Thread(target=portguy) thread_list.append(thread) for thread in thread_list: thread.start() for thread in thread_list: thread.join()

PORTSCANNING IN PYTHON 4

print("Open ports are:", open_ports)

In this function we call the get_ports() function, create a threading list and start threading. The portguy function is our target for threading. After threading we print the open ports list. For this function we have to pass number of ports to be scanned per second as an argument.

run_scanner(700) Different machines perform differently, for me 700 was a good choice.

contact me @[email protected]

You might also like...
Run python scripts and pass data between multiple python and node processes using this npm module

Run python scripts and pass data between multiple python and node processes using this npm module. process-communication has a event based architecture for interacting with python data and errors inside nodejs.

Data Structures and Algorithms Python - Practice data structures and algorithms in python with few small projects

Data Structures and Algorithms All the essential resources and template code nee

🔩 Like builtins, but boltons. 250+ constructs, recipes, and snippets which extend (and rely on nothing but) the Python standard library. Nothing like Michael Bolton.

Boltons boltons should be builtins. Boltons is a set of over 230 BSD-licensed, pure-Python utilities in the same spirit as — and yet conspicuously mis

🔩 Like builtins, but boltons. 250+ constructs, recipes, and snippets which extend (and rely on nothing but) the Python standard library. Nothing like Michael Bolton.

Boltons boltons should be builtins. Boltons is a set of over 230 BSD-licensed, pure-Python utilities in the same spirit as — and yet conspicuously mis

A Python utility belt containing simple tools, a stdlib like feel, and extra batteries. Hashing, Caching, Timing, Progress, and more made easy!
A Python utility belt containing simple tools, a stdlib like feel, and extra batteries. Hashing, Caching, Timing, Progress, and more made easy!

Ubelt is a small library of robust, tested, documented, and simple functions that extend the Python standard library. It has a flat API that all behav

My sister is a GR of her class. She had to mark attendance of students from screenshots of teams meeting on an excel sheet. I resolved her problem by reading names from screenshots using PyTesseract and marking them present on the excel using Pandas in Python. It took me 1hr to write the code and it is saving half an hour everyday.
App and Python library for parsing, writing, and validation of the STAND013 file format.

python-stand013 python-stand013 is a Python app and library for parsing, writing, and validation of the STAND013 file format. Features The following i

OnTime is a small python that you set a time and on that time, app will send you notification and also play an alarm.

OnTime Always be OnTime! What is OnTime? OnTime is a small python that you set a time and on that time, app will send you notification and also play a

Bionic is Python Framework for crafting beautiful, fast user experiences for web and is free and open source.
Bionic is Python Framework for crafting beautiful, fast user experiences for web and is free and open source.

Bionic is Python Framework for crafting beautiful, fast user experiences for web and is free and open source. Getting Started This is an example of ho

Owner
null
This tool for beginner and help those people they gather information about Email Header Analysis, Instagram Information, Instagram Username Check, Ip Information, Phone Number Information, Port Scan

This tool for beginner and help those people they gather information about Email Header Analysis, Instagram Information, Instagram Username Check, Ip Information, Phone Number Information, Port Scan. This tool shows your hostname and public IP first, then user give input and according to option this tool work. This tool work diffrent Oprating system.

cb-kali 5 Feb 18, 2022
A one place destination to check whatever is trending on the top social and news websites at present.

UpTrend A one place destination to check whatever is trending on the top social and news websites at present. Explore the docs » View Demo · Report Bu

Google Developer Student Clubs - JGEC 10 Oct 3, 2021
A framework that let's you compose websites in Python with ease!

Perry Perry <= A framework that let's you compose websites in Python with ease! Perry works similar to Qt and Flutter, allowing you to create componen

Linkus 13 Oct 9, 2022
A script that will warn you, by opening a new browser tab, when there are new content in your favourite websites.

web check A script that will warn you, by opening a new browser tab, when there are new content in your favourite websites. What it does The script wi

Jaime Álvarez 52 Mar 15, 2022
A light library to build tiny websites

A light library to build tiny websites

BT.Q 1 Dec 23, 2021
An awesome list of AI for art and design - resources, and popular datasets and how we may apply computer vision tasks to art and design.

Awesome AI for Art & Design An awesome list of AI for art and design - resources, and popular datasets and how we may apply computer vision tasks to a

Margaret Maynard-Reid 20 Dec 21, 2022
Built with Python programming language and QT library and Guess the number in three easy, medium and hard rolls

guess-the-numbers Built with Python programming language and QT library and Guess the number in three easy, medium and hard rolls Number guessing game

Amir Hussein Sharifnezhad 5 Oct 9, 2021
Built with Python programming language and QT library and Guess the number in three easy, medium and hard rolls

password-generator Built with Python programming language and QT library and Guess the number in three easy, medium and hard rolls Password generator

Amir Hussein Sharifnezhad 3 Oct 9, 2021
Cirq is a Python library for writing, manipulating, and optimizing quantum circuits and running them against quantum computers and simulators

Cirq is a Python library for writing, manipulating, and optimizing quantum circuits and running them against quantum computers and simulators. Install

quantumlib 3.6k Jan 7, 2023
A simple script written using symbolic python that takes as input a desired metric and automatically calculates and outputs the Christoffel Pseudo-Tensor, Riemann Curvature Tensor, Ricci Tensor, Scalar Curvature and the Kretschmann Scalar

A simple script written using symbolic python that takes as input a desired metric and automatically calculates and outputs the Christoffel Pseudo-Tensor, Riemann Curvature Tensor, Ricci Tensor, Scalar Curvature and the Kretschmann Scalar

null 2 Nov 27, 2021