I introduce to you a port scanner i decided to make... very bored
Handler:
Usage
Handler:
PHP Code
<?php
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace Port_Scanner.Handler
{
class ProxyHandler
{
List<int> Ports = new List<int>();
int portindex;
int maxindex;
int minindex;
int currentport;
public ProxyHandler(string range)
{
for (int i = 1; i < int.Parse(range.Split('-')[1]) + 1; i++)
Ports.Add(i);
minindex = Ports.IndexOf(int.Parse(range.Split('-')[0]));
maxindex = Ports.IndexOf(int.Parse(range.Split('-')[1]));
portindex = minindex;
}
public int NextProxy()
{
if (portindex <= maxindex)
{
currentport = Ports[portindex];
portindex++;
}
else
currentport = maxindex + 2;
return currentport;
}
}
}
Usage
PHP Code
<?php
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading;
using System.Net.Sockets;
using Port_Scanner.Handler;
namespace Port_Scanner
{
class Program
{
static ProxyHandler handle;
static int threadcount = 0;
static int amount = 0;
static TcpClient scan;
static string hostname;
static int threadsalive;
static List<int> openports = new List<int>();
static string portrange;
static void Main(string[] args)
{
Console.Write("Threads to use: ");
threadcount = int.Parse(Console.ReadLine());
Console.Write("Hostname: ");
hostname = Console.ReadLine();
Console.Write("Port range(80-100)");
portrange = Console.ReadLine();
DoWork(threadcount);
}
private static void DoWork(int threads)
{
handle = new ProxyHandler(portrange);
Thread[] PortScanner = new Thread[threads];
for (int i = 0; i < threads; i++)
{
PortScanner[i] = new Thread(grabproxy);
PortScanner[i].Start();
}
}
private static void grabproxy()
{
int currentport = 0;
string[] range = portrange.Split('-');
while ((currentport = handle.NextProxy()) != int.Parse(range[1]) + 1)
portscanner(currentport, hostname);
amount++;
Console.WriteLine("Threads finished: " + amount);
threadsalive = threadcount - amount;
if (threadsalive == 0)
{
Console.WriteLine("Job finished");
Console.WriteLine("Open Ports:");
foreach (int port in openports)
Console.WriteLine(port);
Console.Read();
}
}
private static void portscanner(int port, string host)
{
Console.WriteLine("attempting port " + port);
try
{
scan = new TcpClient(host, port);
if (scan.Connected)
openports.Add(port);
}
catch { }
}
}
}


![[Image: Syr3DlV.png]](https://i.imgur.com/Syr3DlV.png)