forked from MortezaBashsiz/CFScanner
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request MortezaBashsiz#146 from MortezaBashsiz/dev
Added some new features to Windows app
- Loading branch information
Showing
16 changed files
with
972 additions
and
160 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,43 +1,78 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Security.Cryptography.X509Certificates; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
using WinCFScan.Classes.IP; | ||
|
||
|
||
namespace WinCFScan.Classes | ||
{ | ||
// load cloudflare ip ranges from 'cf.local.iplist' file | ||
internal class CFIPList | ||
{ | ||
protected string[] ipList { get; set; } | ||
public List<RangeInfo> validIPRanges = new(); | ||
public uint totalIPs = 0; | ||
|
||
public CFIPList(string fileName = "cf.local.iplist") | ||
public CFIPList(string fileName) | ||
{ | ||
loadList(fileName); | ||
} | ||
|
||
private bool loadList(string fileName) | ||
{ | ||
if (!File.Exists(fileName)) | ||
if (!File.Exists(fileName) || (new FileInfo(fileName)).Length > 2 * 1_000_000) | ||
{ | ||
return false; | ||
} | ||
|
||
string fileData = File.ReadAllText(fileName); | ||
|
||
ipList = fileData.Split(); | ||
validateIPList(fileData.Split()); | ||
|
||
return true; | ||
} | ||
|
||
private void validateIPList(string[] loadedIPList) | ||
{ | ||
validIPRanges.Clear(); | ||
totalIPs = 0; | ||
foreach (var ipRange in loadedIPList) | ||
{ | ||
if (IPAddressExtensions.isValidIPRange(ipRange)) | ||
{ | ||
var rangeTotalIPs = IPAddressExtensions.getIPRangeTotalIPs(ipRange); | ||
if (rangeTotalIPs > 0) | ||
{ | ||
this.validIPRanges.Add(new RangeInfo(ipRange, rangeTotalIPs)); | ||
totalIPs += rangeTotalIPs; | ||
} | ||
} | ||
} | ||
} | ||
|
||
public string[] getIPList() | ||
{ | ||
return ipList; | ||
return validIPRanges.Select(x => x.rangeText).ToArray(); | ||
} | ||
|
||
public bool isIPListValid() | ||
{ | ||
return ipList != null && ipList.Length > 0; | ||
return validIPRanges.Count > 0 && totalIPs > 0; | ||
} | ||
} | ||
|
||
public class RangeInfo{ | ||
public string rangeText; | ||
public uint totalIps; | ||
|
||
public RangeInfo(string rangeText, uint totalIps) | ||
{ | ||
this.rangeText = rangeText; | ||
this.totalIps = totalIps; | ||
} | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.