Skip to content

Commit

Permalink
add privacy masking feature
Browse files Browse the repository at this point in the history
  • Loading branch information
Archeb committed Mar 16, 2024
1 parent 859bd75 commit 393507e
Show file tree
Hide file tree
Showing 10 changed files with 202 additions and 3 deletions.
47 changes: 47 additions & 0 deletions NextTraceWrapper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -321,6 +321,53 @@ private TracerouteResult ProcessLine(string line)
Geolocation = Resources.LOOPBACK_ADDR;
}

// 打码 IP 地址
// maskedHopsMode 设置包含 ip_half, ip_full, ip_geo, all 四种打码模式
// maskedHops 指示打码的跳数


if (UserSettings.maskedHops > 0 && int.Parse(No) <= UserSettings.maskedHops)
{
if (UserSettings.maskedHopsMode == "ip_half")
{
if (IP.Contains(":"))
{
// IPv6 全部打码
IP = "****";
}
else if (IP.Contains("."))
{
// IPv4 打码后 2 节
IP = string.Join(".", IP.Split('.').Take(2).Concat(new string[] { "xx", "xx" }));
}
// 删除主机名
Hostname = "";
}
else if (UserSettings.maskedHopsMode == "ip_full")
{
IP = "****";
// 删除主机名
Hostname = "";
}
else if (UserSettings.maskedHopsMode == "ip_geo")
{
IP = "****";
Geolocation = "****";
// 删除主机名
Hostname = "";
}
else if (UserSettings.maskedHopsMode == "all")
{
IP = "****";
Geolocation = "****";
AS = "****";
Hostname = "";
Organization = "****";
Latitude = "****";
Longitude = "****";
}
}


return new TracerouteResult(No, IP, Time, Geolocation, AS, Hostname, Organization, Latitude, Longitude);
}
Expand Down
2 changes: 1 addition & 1 deletion OpenTrace.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
<Title>OpenTrace</Title>
<ApplicationIcon>icon.ico</ApplicationIcon>
<PackageIcon>icon.png</PackageIcon>
<Version>1.4.2.1</Version>
<Version>1.4.3.0</Version>
<Platforms>AnyCPU;x64</Platforms>
<PlatformTarget>AnyCPU</PlatformTarget>

Expand Down
16 changes: 16 additions & 0 deletions PreferencesDialog.xeto
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,22 @@
<Label Text="{x:Static resource:Resources.GRID_SIZE_RATIO}"></Label>
<NumericStepper x:Name="gridSizePercentage" MaxValue="90" MinValue="10" ></NumericStepper>
</TableRow>

<TableRow>
<Label Text="{x:Static resource:Resources.PRIVACY_MASKING}"></Label>
<TableLayout Spacing="5,5">
<TableRow>
<Label Text="{x:Static resource:Resources.PRIVACY_MASKING_DESCR}"></Label>
<NumericStepper x:Name="maskedHops" MaxValue="30" MinValue="0" ></NumericStepper>
<DropDown x:Name="maskedHopsMode" SelectedIndex="0">
<ListItem Text="{x:Static resource:Resources.PRIVACY_MASKING_IP_HALF}" Key="ip_half"></ListItem>
<ListItem Text="{x:Static resource:Resources.PRIVACY_MASKING_IP_FULL}" Key="ip_full"></ListItem>
<ListItem Text="{x:Static resource:Resources.PRIVACY_MASKING_IP_GEO}" Key="ip_geo"></ListItem>
<ListItem Text="{x:Static resource:Resources.PRIVACY_MASKING_ALL}" Key="all"></ListItem>
</DropDown>
</TableRow>
</TableLayout>
</TableRow>
</TableLayout>
</TableRow>
<TableRow>
Expand Down
2 changes: 2 additions & 0 deletions PreferencesDialog.xeto.cs
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ private void ApplyUserSettings()
}
}
this.FindChild<NumericStepper>("gridSizePercentage").Value = UserSettings.gridSizePercentage * 100;
this.FindChild<NumericStepper>("maskedHops").Value = UserSettings.maskedHops;
}

private void CancelButton_Click(object sender, EventArgs e)
Expand Down Expand Up @@ -81,6 +82,7 @@ private void SaveButton_Click(object sender, EventArgs e)
}
}
UserSettings.gridSizePercentage = this.FindChild<NumericStepper>("gridSizePercentage").Value / 100;
UserSettings.maskedHops = (int)this.FindChild<NumericStepper>("maskedHops").Value;
UserSettings.SaveSettings();
IPDBLoader.Load();
Close();
Expand Down
60 changes: 58 additions & 2 deletions Properties/Resources.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

18 changes: 18 additions & 0 deletions Properties/Resources.resx
Original file line number Diff line number Diff line change
Expand Up @@ -501,4 +501,22 @@ And restart OpenTrace after execution.</value>
<data name="UPDATE_AVAILABLE" xml:space="preserve">
<value>(Version {0} now available. Download it from the Help menu.)</value>
</data>
<data name="PRIVACY_MASKING" xml:space="preserve">
<value>Privacy Masking</value>
</data>
<data name="PRIVACY_MASKING_ALL" xml:space="preserve">
<value>hops by masking all info</value>
</data>
<data name="PRIVACY_MASKING_DESCR" xml:space="preserve">
<value>Protect the first</value>
</data>
<data name="PRIVACY_MASKING_IP_FULL" xml:space="preserve">
<value>hops by fully masking IP</value>
</data>
<data name="PRIVACY_MASKING_IP_GEO" xml:space="preserve">
<value>hops by masking IP and Geo</value>
</data>
<data name="PRIVACY_MASKING_IP_HALF" xml:space="preserve">
<value>hops by partially masking IP</value>
</data>
</root>
18 changes: 18 additions & 0 deletions Properties/Resources.zh-CN.resx
Original file line number Diff line number Diff line change
Expand Up @@ -496,4 +496,22 @@ sudo xattr -r -d com.apple.quarantine &lt;将 OpenTrace 拖放至此&gt;
<data name="UPDATE_AVAILABLE" xml:space="preserve">
<value>(最新版 {0} 已发布,可到帮助菜单下载)</value>
</data>
<data name="PRIVACY_MASKING" xml:space="preserve">
<value>隐私保护</value>
</data>
<data name="PRIVACY_MASKING_ALL" xml:space="preserve">
<value>跳的所有信息</value>
</data>
<data name="PRIVACY_MASKING_DESCR" xml:space="preserve">
<value>打码前</value>
</data>
<data name="PRIVACY_MASKING_IP_FULL" xml:space="preserve">
<value>跳的完整 IP</value>
</data>
<data name="PRIVACY_MASKING_IP_GEO" xml:space="preserve">
<value>跳的 IP 和地理位置</value>
</data>
<data name="PRIVACY_MASKING_IP_HALF" xml:space="preserve">
<value>跳的部分 IP</value>
</data>
</root>
18 changes: 18 additions & 0 deletions Properties/Resources.zh-HK.resx
Original file line number Diff line number Diff line change
Expand Up @@ -411,6 +411,24 @@ sudo chmod +sx /path/to/nexttrace
<data name="PREFERENCES" xml:space="preserve">
<value>設置</value>
</data>
<data name="PRIVACY_MASKING" xml:space="preserve">
<value>私隱保護</value>
</data>
<data name="PRIVACY_MASKING_ALL" xml:space="preserve">
<value>跳的所有訊息</value>
</data>
<data name="PRIVACY_MASKING_DESCR" xml:space="preserve">
<value>隱藏前</value>
</data>
<data name="PRIVACY_MASKING_IP_FULL" xml:space="preserve">
<value>跳的完整 IP</value>
</data>
<data name="PRIVACY_MASKING_IP_GEO" xml:space="preserve">
<value>跳的 IP 與地理位置</value>
</data>
<data name="PRIVACY_MASKING_IP_HALF" xml:space="preserve">
<value>跳的部分 IP</value>
</data>
<data name="PRIVATE_ADDR" xml:space="preserve">
<value>私有地址(局域網)</value>
</data>
Expand Down
18 changes: 18 additions & 0 deletions Properties/Resources.zh-TW.resx
Original file line number Diff line number Diff line change
Expand Up @@ -411,6 +411,24 @@ sudo chmod +sx /path/to/nexttrace
<data name="PREFERENCES" xml:space="preserve">
<value>設定</value>
</data>
<data name="PRIVACY_MASKING" xml:space="preserve">
<value>私隱保護</value>
</data>
<data name="PRIVACY_MASKING_ALL" xml:space="preserve">
<value>跳的所有訊息</value>
</data>
<data name="PRIVACY_MASKING_DESCR" xml:space="preserve">
<value>隱藏前</value>
</data>
<data name="PRIVACY_MASKING_IP_FULL" xml:space="preserve">
<value>跳的完整 IP</value>
</data>
<data name="PRIVACY_MASKING_IP_GEO" xml:space="preserve">
<value>跳的 IP 與地理位置</value>
</data>
<data name="PRIVACY_MASKING_IP_HALF" xml:space="preserve">
<value>跳的部分 IP</value>
</data>
<data name="PRIVATE_ADDR" xml:space="preserve">
<value>私有地址(區域網)</value>
</data>
Expand Down
6 changes: 6 additions & 0 deletions UserSettings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -120,5 +120,11 @@ internal class UserSettings : Advexp.Settings<UserSettings>

[Setting(Name = "checkUpdateOnStartup", Default = true)]
public static bool checkUpdateOnStartup { get; set; }

[Setting(Name = "maskedHops", Default = 0)]
public static int maskedHops { get; set; }

[Setting(Name = "maskedHopsMode", Default = "ip_half")]
public static string maskedHopsMode { get; set; }
}
}

0 comments on commit 393507e

Please sign in to comment.