Skip to content

Commit

Permalink
.
Browse files Browse the repository at this point in the history
  • Loading branch information
a.hosseini committed May 21, 2024
1 parent eb4c2b9 commit b927c3f
Showing 1 changed file with 5 additions and 12 deletions.
17 changes: 5 additions & 12 deletions fast cf ip scanner/Services/IPService.cs
Original file line number Diff line number Diff line change
@@ -1,14 +1,10 @@


using fast_cf_ip_scanner.Data;
using fast_cf_ip_scanner.Data;
using Microsoft.Maui.Animations;
using System.Collections.Concurrent;
using System.Diagnostics;
using System.Net;
using System.Net.NetworkInformation;
using System.Net.Sockets;


namespace fast_cf_ip_scanner.Services
{
public class IPService
Expand All @@ -26,7 +22,6 @@ public async Task<List<IPModel>> GetIpValid(string[] ips, IpOptionModel ipOption
var validIps = new List<IPModel>();
switch (protcol)
{

case "Http test":
validIps = await GetValidٌIPWithHttpTest(ips, ipOptions);
break;
Expand All @@ -38,6 +33,7 @@ public async Task<List<IPModel>> GetIpValid(string[] ips, IpOptionModel ipOption
//case "UDP test":
// validIps = await GetValidIPWithUDPTest(ips, ipOptions);
// break;

case "Terminal Ping test":
validIps = await GetValidIpWithPingTest(ips, ipOptions);
break;
Expand All @@ -51,7 +47,6 @@ public async Task<List<IPModel>> GetIpValid(string[] ips, IpOptionModel ipOption

public async Task<List<IPModel>> GetValidٌIPWithHttpTest(string[] ips, IpOptionModel ipOptions)
{

var validIp = new ConcurrentBag<IPModel>();

async Task HttpTest(string ipAddresse)
Expand All @@ -71,7 +66,6 @@ async Task HttpTest(string ipAddresse)
{
foreach (var port in ipOptions.Ports)
{

try
{
stopwatch.Start();
Expand All @@ -92,7 +86,7 @@ async Task HttpTest(string ipAddresse)
}
}
}
if (ports.Any())
if (ports.Count > 0)
{
var totalPing = Convert.ToInt32(stopwatch.Elapsed.TotalMilliseconds);
int ping = totalPing / (ipOptions.CountOfRepeatTestForEachIp * ipOptions.Ports.Count);
Expand Down Expand Up @@ -181,7 +175,7 @@ async Task TestConnectionAsync(string ip)
}
}

if (ports.Any())
if (ports.Count > 0)
{
int ping = totalPing / (ipOptions.CountOfRepeatTestForEachIp * ipOptions.Ports.Count);

Expand Down Expand Up @@ -221,7 +215,6 @@ async Task TestConnectionAsync(string ip)

public async Task<List<IPModel>> GetValidIPWithUDPTest(string[] ips, int maxPing)
{

var validIp = new ConcurrentBag<IPModel>();
var randips = GetRandomIp(ips);
foreach (var ipAddresse in randips)
Expand Down Expand Up @@ -350,7 +343,6 @@ async Task TestConnectionAsync(string ipAddress)

public List<string> GetRandomIp(string[] ips, int ipCount = 20, int ipRangeCount = 4)
{

Random random = new Random();

var randomIpRange = new List<string>();
Expand Down Expand Up @@ -388,6 +380,7 @@ public string[] GetRandomPort(int count = 3)
int randomIndex = random.Next(allPorts.Count);
randomPorts[i] = allPorts[randomIndex];
}

return randomPorts;
}

Expand Down

0 comments on commit b927c3f

Please sign in to comment.