Skip to content

Commit 9d03da9

Browse files
author
a.hosseini
committed
fixe ip Addresses.txt
1 parent 91503a3 commit 9d03da9

File tree

3 files changed

+19
-3
lines changed

3 files changed

+19
-3
lines changed

fast cf ip scanner/Services/IPServices.cs

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,16 +6,31 @@
66
using System.Net.NetworkInformation;
77
using System.Net.WebSockets;
88
using System.Reflection;
9+
using System.Resources;
910

1011
namespace fast_cf_ip_scanner.Services
1112
{
1213
public class IPServices
1314
{
15+
List<string> ipAddresses = new List<string>();
1416
public IPServices()
1517
{
18+
1619
}
20+
21+
1722
public async Task<List<IPModel>> GetIpValid(int maxPing)
1823
{
24+
if (ipAddresses.Count == 0)
25+
{
26+
using var stream = await FileSystem.OpenAppPackageFileAsync("IPAddresses.txt");
27+
using var reader = new StreamReader(stream);
28+
string line;
29+
while ((line = await reader.ReadLineAsync()) != null)
30+
{
31+
ipAddresses.Add(line);
32+
}
33+
}
1934
SocketsHttpHandler SocketsHandler = new SocketsHttpHandler();
2035
HttpClient Client = new HttpClient(SocketsHandler)
2136
{
@@ -68,10 +83,9 @@ public async Task<List<IPModel>> GetIpValid(int maxPing)
6883
}
6984
string GetRandomIp()
7085
{
71-
var path = Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), @"IPAddresses.txt");
72-
var ipAddresses = File.ReadAllLines(path);
86+
// var path = Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), @"IPAddresses.txt");
7387
Random random = new Random();
74-
return ipAddresses[random.Next(ipAddresses.Length)];
88+
return ipAddresses[random.Next(ipAddresses.Count)];
7589
}
7690
}
7791
}

fast cf ip scanner/ViewModels/MainPageViewModel.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ int ConvertMaxPingOfIPToInt(string maxPing)
5555
}
5656

5757
}
58+
5859
[RelayCommand]
5960
async Task CopySelectedIPAsync(IPModel iPModel)
6061
{

fast cf ip scanner/fast cf ip scanner.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@
4646

4747
<!-- Raw Assets (also remove the "Resources\Raw" prefix) -->
4848
<MauiAsset Include="Resources\Raw\**" LogicalName="%(RecursiveDir)%(Filename)%(Extension)" />
49+
<MauiAsset Include="Resources\Raw\IPAddresses.txt" />
4950
</ItemGroup>
5051

5152
<ItemGroup>

0 commit comments

Comments
 (0)