Welcome to HBH! If you have tried to register and didn't get a verification email, please using the following link to resend the verification email.
Mono PortScanner - C# Code Bank
Mono PortScanner
usage: portscan <ipAddress> <minPort> <maxPort>
compiler: gmcs
//program.cs
using System;
using System.Net;
using System.Net.Sockets;
namespace SharpScanner
{
class Program
{
public static void Main(string[] args)
{
if(args[0] == "help")
{
Console.WriteLine("Usage: portscan <ip address> <min port> <max port>");
}
else
{
string ipAddress = args[0];
int minPort = Convert.ToInt32(args[1]);
int maxPort = Convert.ToInt32(args[2]);
PortScanner scan = new PortScanner(ipAddress, minPort, maxPort);
scan.run();
}
}
}
}
//PortScanner.cs
using System;
using System.Net;
using System.Net.Sockets;
namespace SharpScanner
{
class PortScanner
{
public int maxPort;
public int minPort;
public IPAddress ipAddress;
private TcpClient scan;
public PortScanner(String ip, int min, int max)
{
ipAddress = IPAddress.Parse(ip);
minPort = min;
maxPort = max;
scan = new TcpClient();
}
public void run()
{
for(int currentPort = minPort; currentPort < maxPort; currentPort++)
{
scan = new TcpClient();
try
{
scan.Connect(ipAddress, currentPort);
Console.WriteLine("Port: {0} is open", currentPort);
}
catch
{
continue;
}
}
}
}
}