-
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
18 changed files
with
878 additions
and
726 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
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
File renamed without changes.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,111 @@ | ||
using Newtonsoft.Json.Linq; | ||
using System.Net; | ||
using System.Net.Http; | ||
using System.Windows; | ||
using System.Windows.Threading; | ||
|
||
namespace CheckIP.Common | ||
{ | ||
public class IPManager | ||
{ | ||
public class IP | ||
{ | ||
public string City { get; set; } | ||
public string Country { get; set; } | ||
public string CountryCode { get; set; } | ||
public string Postal { get; set; } | ||
public string Timezone { get; set; } | ||
public string Latitude { get; set; } | ||
public string Longitude { get; set; } | ||
public string Isp { get; set; } | ||
public string Asn { get; set; } | ||
public bool Mobile { get; set; } | ||
public bool Proxy { get; set; } | ||
public bool Hosting { get; set; } | ||
public bool ParseSuccess { get; set; } | ||
public string Status { get; set; } | ||
public IPAddress IPAddress { get; set; } | ||
} | ||
|
||
public static IP Parse(string ip) | ||
{ | ||
var ipData = new IP(); | ||
|
||
var validateIp = IPAddress.TryParse(ip, out var ipAddr); | ||
if (!validateIp) | ||
{ | ||
ipData.ParseSuccess = false; | ||
Application.Current.Dispatcher.Invoke(() => | ||
{ | ||
var error = (string)Application.Current.MainWindow!.FindResource("ErrorInvalidIP"); | ||
ipData.Status = !string.IsNullOrEmpty(error) ? error : "Error: This is not a valid IP address."; | ||
}); | ||
return ipData; | ||
} | ||
|
||
// Parse data | ||
string dataJson; | ||
var url = "http://ip-api.com/json/" + ip + "?fields=status,message,country,countryCode,city,zip,lat,lon,timezone,isp,as,mobile,proxy,hosting"; | ||
try | ||
{ | ||
var client = new HttpClient(); | ||
using var response = client.GetAsync(url).Result; | ||
using var content = response.Content; | ||
dataJson = content.ReadAsStringAsync().Result; | ||
} | ||
catch | ||
{ | ||
ipData.ParseSuccess = false; | ||
Application.Current.Dispatcher.Invoke(() => | ||
{ | ||
var error = (string)Application.Current.MainWindow!.FindResource("ErrorNoConnection"); | ||
ipData.Status = !string.IsNullOrEmpty(error) ? error : "Error: No connection to server"; | ||
}); | ||
return ipData; | ||
} | ||
dynamic data = JObject.Parse(dataJson); | ||
|
||
// Parse data | ||
string status = data.status; | ||
string message = data.message; | ||
string country = data.country; | ||
string countryCode = data.countryCode; | ||
string city = data.city; | ||
string postal = data.zip; | ||
string timezone = data.timezone; | ||
string latitude = data.lat; | ||
string longitude = data.lon; | ||
string isp = data.isp; | ||
string asn = data.@as; | ||
string mobile = data.mobile; | ||
string proxy = data.proxy; | ||
string hosting = data.hosting; | ||
|
||
// Check status | ||
if (status != "success") | ||
{ | ||
var localizeError = Common.LocalizationManager.LocalizeError(message); | ||
ipData.Status = localizeError; | ||
ipData.ParseSuccess = false; | ||
return ipData; | ||
} | ||
|
||
ipData.City = city; | ||
ipData.Country = country; | ||
ipData.CountryCode = countryCode; | ||
ipData.Postal = postal; | ||
ipData.Timezone = timezone; | ||
ipData.Latitude = latitude; | ||
ipData.Longitude = longitude; | ||
ipData.Isp = isp; | ||
ipData.Asn = asn; | ||
ipData.Mobile = mobile.Equals("true", System.StringComparison.CurrentCultureIgnoreCase); | ||
ipData.Proxy = proxy.Equals("true", System.StringComparison.CurrentCultureIgnoreCase); | ||
ipData.Hosting = hosting.Equals("true", System.StringComparison.CurrentCultureIgnoreCase); | ||
ipData.IPAddress = ipAddr; | ||
ipData.ParseSuccess = true; | ||
|
||
return ipData; | ||
} | ||
} | ||
} |
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
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 |
---|---|---|
@@ -0,0 +1,74 @@ | ||
<ui:FluentWindow x:Class="CheckIP.MainWindow" | ||
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" | ||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" | ||
Title="CheckIP" Height="669" Width="512" | ||
MinHeight="669" MinWidth="512" | ||
xmlns:pages="clr-namespace:CheckIP" | ||
xmlns:ui="http://schemas.lepo.co/wpfui/2022/xaml" | ||
WindowStartupLocation="CenterScreen" | ||
ExtendsContentIntoTitleBar="True" | ||
WindowBackdropType="Mica" | ||
WindowCornerPreference="Round" | ||
ResizeMode="NoResize" | ||
ContentRendered="MainWindow_OnContentRendered"> | ||
<Grid> | ||
<Grid.RowDefinitions> | ||
<RowDefinition Height="Auto" /> | ||
<RowDefinition Height="*" /> | ||
</Grid.RowDefinitions> | ||
|
||
<Grid Grid.Row="1" Margin="0"> | ||
<Grid.RowDefinitions> | ||
<RowDefinition Height="*" /> | ||
<RowDefinition Height="Auto" /> | ||
</Grid.RowDefinitions> | ||
|
||
<ui:NavigationView x:Name="RootNavigation" PaneDisplayMode="Top" IsBackButtonVisible="Collapsed" Margin="6,0" Grid.Row="0"> | ||
<ui:NavigationView.MenuItems> | ||
<ui:NavigationViewItem Content="{DynamicResource Fetch}" NavigationCacheMode="Enabled" TargetPageType="{x:Type pages:FetchIP}"> | ||
<ui:NavigationViewItem.Icon> | ||
<ui:SymbolIcon Symbol="Search24" /> | ||
</ui:NavigationViewItem.Icon> | ||
</ui:NavigationViewItem> | ||
<ui:NavigationViewItem Content="{DynamicResource MyIP}" NavigationCacheMode="Enabled" TargetPageType="{x:Type pages:MyIP}"> | ||
<ui:NavigationViewItem.Icon> | ||
<ui:SymbolIcon Symbol="MyLocation24" /> | ||
</ui:NavigationViewItem.Icon> | ||
</ui:NavigationViewItem> | ||
</ui:NavigationView.MenuItems> | ||
|
||
<ui:NavigationView.FooterMenuItems> | ||
<ui:NavigationViewItem Click="ThemeSwitch_Click"> | ||
<ui:NavigationViewItem.Icon> | ||
<ui:SymbolIcon Symbol="PaintBrush24"/> | ||
</ui:NavigationViewItem.Icon> | ||
</ui:NavigationViewItem> | ||
<ui:NavigationViewItem TargetPageType="{x:Type pages:About}" NavigationCacheMode="Enabled"> | ||
<ui:NavigationViewItem.Icon> | ||
<ui:SymbolIcon Symbol="QuestionCircle24" /> | ||
</ui:NavigationViewItem.Icon> | ||
</ui:NavigationViewItem> | ||
</ui:NavigationView.FooterMenuItems> | ||
</ui:NavigationView> | ||
</Grid> | ||
|
||
<ui:TitleBar | ||
Title="CheckIP" | ||
ShowMinimize="False" | ||
ShowMaximize="False" | ||
Grid.Row="0"> | ||
<ui:TitleBar.Icon> | ||
<ui:ImageIcon Source="pack://application:,,,/Assets/CheckIP.ico" /> | ||
</ui:TitleBar.Icon> | ||
</ui:TitleBar> | ||
|
||
<Grid Grid.Row="0"> | ||
<Grid.ColumnDefinitions> | ||
<ColumnDefinition Width="*"/> | ||
<ColumnDefinition Width="*"/> | ||
</Grid.ColumnDefinitions> | ||
|
||
<TextBlock Grid.Column="1" x:Name="DebugString" Text="Debug" Margin="0,17,50,0" Foreground="Red" TextAlignment="Right" HorizontalAlignment="Right"/> | ||
</Grid> | ||
</Grid> | ||
</ui:FluentWindow> |
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.