GithubHelp home page GithubHelp logo

liragbr / portscanner Goto Github PK

View Code? Open in Web Editor NEW
1.0 1.0 0.0 6 KB

PortScanner is a C# tool for identifying open ports on target systems, crucial for network security. It offers fast, multi-threaded scanning and detailed reports, perfect for network administrators and cybersecurity professionals.

License: MIT License

C# 100.00%
csharp csharp-code cybersecurity hacker hackertools multithreading networkanalysis networksecurity networktools openports penetrationtesting portscanner portscanning security systemsecurity tcpclient tools

portscanner's Introduction

๐Ÿฅท๐Ÿป Port Scanner

Warning

I made this project in order to improve my programming logic and better understand some cybersecurity and c# issues, the code was not tested in production that is, it may contain flaws, always have explicit permission before scanning ports on systems that are not yours. Door scanners can be misinterpreted as intrusion attempts

Introduction

this project is a port scanning tool developed in C#. Port scanning is a crucial technique used in network security to identify open ports and services available on a target system. This tool helps in identifying potential vulnerabilities by scanning for open ports and understanding the services running on them.

Port scanning works by sending packets to specified ports on a target system and analyzing the responses. It is widely used by network administrators for security assessments and by attackers for reconnaissance. The key features of this PortScanner include:

  • Multi-threaded Scanning: Enhances performance by scanning multiple ports simultaneously.
  • Customizable Scanning Options: Allows users to specify the range of ports and the IP addresses to scan.
  • Detailed Reporting: Provides comprehensive reports on the open ports and services detected. This repository is designed to be a valuable resource for cybersecurity professionals, network administrators, and developers interested in network security.

Usage

  • Run the executable or start debugging from your development environment.
  • Specify the target IP address and the range of ports you want to scan.
  • Start the scan and view the results in the output window.

Code Overview

CommandExecutor.cs

The CommandExecutor class is responsible for executing system commands to gather network information.

public class CommandExecutor
{
    public static string ExecuteCommand(string command)
    {
        // Initializes a new process to execute the command
        ProcessStartInfo procStartInfo = new ProcessStartInfo("cmd", "/c " + command)
        {
            RedirectStandardOutput = true,
            UseShellExecute = false,
            CreateNoWindow = true
        };

        // Starts the process
        Process proc = new Process
        {
            StartInfo = procStartInfo
        };
        proc.Start();

        // Reads the output of the command
        return proc.StandardOutput.ReadToEnd();
    }
}
This function uses ProcessStartInfo to set up the command execution environment and Process to run the command and capture its output.

PortScanner.cs

The PortScanner class handles the scanning logic.

public class PortScanner
{
    private string targetIP;
    private int startPort;
    private int endPort;

    public PortScanner(string ip, int start, int end)
    {
        targetIP = ip;
        startPort = start;
        endPort = end;
    }

    public void Scan()
    {
        Parallel.For(startPort, endPort + 1, port =>
        {
            // Attempts to connect to the port
            using (TcpClient tcpClient = new TcpClient())
            {
                try
                {
                    tcpClient.Connect(targetIP, port);
                    Console.WriteLine($"Port {port} is open.");
                }
                catch (Exception)
                {
                    Console.WriteLine($"Port {port} is closed.");
                }
            }
        });
    }
}

This class sets up the scanning parameters and uses Parallel.For to scan ports concurrently, enhancing the scan speed significantly.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.