main
jeffrey 2025-03-29 09:54:44 +01:00
parent 8b0f909a10
commit 4bf0c12507
1 changed files with 80 additions and 74 deletions

View File

@ -14,6 +14,10 @@ using System.Threading.Tasks;
namespace SharpScan namespace SharpScan
{ {
class Program
{
public class Options public class Options
{ {
[Option('h', "hosts", Required = true, Separator = ',', HelpText = "Hosts to scan, coma separated. CIDR accepted")] [Option('h', "hosts", Required = true, Separator = ',', HelpText = "Hosts to scan, coma separated. CIDR accepted")]
@ -38,9 +42,6 @@ namespace SharpScan
public int TopPorts { get; set; } public int TopPorts { get; set; }
} }
class Program
{
public static List<string> GetIpsFromCidr(string cidr) public static List<string> GetIpsFromCidr(string cidr)
{ {
@ -134,9 +135,7 @@ namespace SharpScan
} }
} }
static void RunOptions(Options o)
static void Main(string[] args)
{ {
List<(string address, int port)> cibles = new List<(string address, int port)>(); List<(string address, int port)> cibles = new List<(string address, int port)>();
List<string> addresses = new List<string>(); List<string> addresses = new List<string>();
@ -149,9 +148,6 @@ namespace SharpScan
int jittler = 0; int jittler = 0;
int top_port = 0; int top_port = 0;
Parser.Default.ParseArguments<Options>(args).WithParsed<Options>(o => {
// Gestion des hosts // Gestion des hosts
foreach (string host in o.Hosts) foreach (string host in o.Hosts)
{ {
@ -209,9 +205,6 @@ namespace SharpScan
delay = o.Delay; delay = o.Delay;
jittler = o.Jittler; jittler = o.Jittler;
top_port = o.TopPorts; top_port = o.TopPorts;
});
// Construction des cibles // Construction des cibles
foreach (string address in addresses) foreach (string address in addresses)
@ -252,7 +245,7 @@ namespace SharpScan
foreach ((string address, int port) in cibles) foreach ((string address, int port) in cibles)
{ {
if( cpt % fraction == 0) if (cpt % fraction == 0)
{ {
cpt_fraction += 10; cpt_fraction += 10;
Console.WriteLine($"Request {cpt}/{cibles.Count} ({cpt_fraction})%"); Console.WriteLine($"Request {cpt}/{cibles.Count} ({cpt_fraction})%");
@ -293,6 +286,19 @@ namespace SharpScan
} }
Console.WriteLine($" {port} opened ({Utils.GetDesc(port)})"); Console.WriteLine($" {port} opened ({Utils.GetDesc(port)})");
} }
}
static void HandleParseError(IEnumerable<Error> errs)
{
//handle errors
}
static void Main(string[] args)
{
CommandLine.Parser.Default.ParseArguments<Options>(args)
.WithParsed(RunOptions)
.WithNotParsed(HandleParseError);
} }
} }
} }