Skip to content

Commit

Permalink
- Adding Ignore filter
Browse files Browse the repository at this point in the history
- Updating RestSharp
  • Loading branch information
Gael authored and Gael committed Jul 31, 2021
1 parent f2be750 commit 33d5eb7
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 7 deletions.
1 change: 1 addition & 0 deletions IPABan/Configuration.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,6 @@ public class Configuration
public int attemptPermaBan = 3;
public int attempBeforeBan = 5;
public int debugLevel = 0;
public string[] filterIp = { "10.0.0.*", "127.0.0.1" };
}
}
4 changes: 2 additions & 2 deletions IPABan/IPABan.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,8 @@
<Reference Include="Newtonsoft.Json, Version=13.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed, processorArchitecture=MSIL">
<HintPath>..\packages\Newtonsoft.Json.13.0.1\lib\net45\Newtonsoft.Json.dll</HintPath>
</Reference>
<Reference Include="RestSharp, Version=106.11.7.0, Culture=neutral, PublicKeyToken=598062e77f915f75, processorArchitecture=MSIL">
<HintPath>..\packages\RestSharp.106.11.7\lib\net452\RestSharp.dll</HintPath>
<Reference Include="RestSharp, Version=106.12.0.0, Culture=neutral, PublicKeyToken=598062e77f915f75, processorArchitecture=MSIL">
<HintPath>..\packages\RestSharp.106.12.0\lib\net452\RestSharp.dll</HintPath>
</Reference>
<Reference Include="System" />
<Reference Include="System.Configuration.Install" />
Expand Down
41 changes: 37 additions & 4 deletions IPABan/Service1.cs
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,8 @@ void LoadConfiguration()
}

protected override void OnStart(string[] args)
{
{

WriteToFile("Service is started. " + DateTime.Now);
LoadConfiguration();
LoadBanList();
Expand Down Expand Up @@ -355,10 +356,17 @@ private void OnEntryWritten(object source, EntryWrittenEventArgs e)

}
if (reader.GetAttribute(0) == "IpAddress")
{
{


string ipAddress = reader.ReadElementContentAsString();


if (CheckFilter(ipAddress))
{
WriteLog("Ignore IP : " + ipAddress);
return;
}


int idxIP = FindIP(ipAddress);
if (idxIP == -1)
{
Expand Down Expand Up @@ -416,6 +424,31 @@ private void OnEntryWritten(object source, EntryWrittenEventArgs e)
}
}

bool CheckFilter(string _ip)
{
string[] ip = _ip.Split('.');
foreach(string s in Config.filterIp)
{
string[] spl = s.Split('.');
if(spl[0] == ip[0] || spl[0] == "*")
{
if (spl[1] == ip[1] || spl[1] == "*")
{
if (spl[2] == ip[2] || spl[2] == "*")
{
if (spl[3] == ip[3] || spl[3] == "*")
{
return true;
}
}
}
}
}

return false;
}


void FirewallUpdate()
{
try
Expand Down
2 changes: 1 addition & 1 deletion IPABan/packages.config
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="Newtonsoft.Json" version="13.0.1" targetFramework="net472" />
<package id="RestSharp" version="106.11.7" targetFramework="net472" />
<package id="RestSharp" version="106.12.0" targetFramework="net472" />
<package id="WindowsFirewallHelper" version="1.6.3.40" targetFramework="net472" />
</packages>

0 comments on commit 33d5eb7

Please sign in to comment.