Skip to content

Commit

Permalink
Added the possibility to get the user's current IP (#177)
Browse files Browse the repository at this point in the history
  • Loading branch information
Leo-Peyronnet committed Mar 20, 2021
1 parent cbb6d58 commit 9851a2e
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 5 deletions.
2 changes: 1 addition & 1 deletion InternetTest/InternetTest/Classes/Global.cs
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ public async static Task<IPInfo> GetIPInfo(string ip)
TimeZone = lines[9],
ISP = lines[10],
Org = lines[12],
Query = lines[lines.Length - 1]
Query = lines[13]
};
}
catch (Exception ex)
Expand Down
3 changes: 1 addition & 2 deletions InternetTest/InternetTest/Classes/IPInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -101,8 +101,7 @@ public class IPInfo

public override string ToString()
{
return $"{Properties.Resources.MyIP}: {Query}\n" +
$"{Properties.Resources.Country}: {Country}\n" +
return $"{Properties.Resources.Country}: {Country}\n" +
$"{Properties.Resources.Region}: {RegionName}\n" +
$"{Properties.Resources.City}: {City}\n" +
$"{Properties.Resources.ZIPCode}: {Zip}\n" +
Expand Down
1 change: 1 addition & 0 deletions InternetTest/InternetTest/Pages/LocalizeIPPage.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
<TextBox x:Name="IPTxt" Style="{DynamicResource TextBoxStyle1}" Margin="10" Padding="5" Background="{x:Null}" BorderBrush="{Binding Source={StaticResource AccentColor}}" SelectionBrush="{Binding Source={StaticResource AccentColor}}" CaretBrush="{Binding Source={StaticResource Foreground1}}"/>
<StackPanel Orientation="Horizontal" VerticalAlignment="Center" HorizontalAlignment="Center">
<Button x:Name="LocalizeBtn" Click="LocalizeBtn_Click" Content="{x:Static lang:Resources.LocalizeIP}" HorizontalAlignment="Center" Padding="10,5,10,5" Style="{StaticResource TabButtonStyle}" Foreground="{Binding Source={StaticResource WindowButtonsHoverForeground1}}" Background="{Binding Source={StaticResource AccentColor}}" FontWeight="Bold" Margin="0,10,10,0"/>
<Button x:Name="MyIPBtn" Click="MyIPBtn_Click" Content="{x:Static lang:Resources.MyIP}" HorizontalAlignment="Center" Padding="10,5,10,5" Style="{StaticResource TabButtonStyle}" Foreground="{Binding Source={StaticResource Foreground1}}" Background="{Binding Source={StaticResource Background2}}" FontWeight="Bold" Margin="0,10,0,0"/>
<Button x:Name="OpenMapBtn" Click="OpenMapBtn_Click" Content="{x:Static lang:Resources.OpenMap}" HorizontalAlignment="Center" Padding="10,5,10,5" Style="{StaticResource TabButtonStyle}" Foreground="{Binding Source={StaticResource Foreground1}}" Background="{Binding Source={StaticResource Background2}}" FontWeight="Bold" Margin="0,10,0,0"/>
</StackPanel>
<TextBlock x:Name="IPInfoTxt" d:Text="IP infos here" HorizontalAlignment="Left" FontWeight="Bold" FontSize="16" Margin="10,10,0,0" Foreground="{Binding Source={StaticResource Foreground1}}"/>
Expand Down
16 changes: 14 additions & 2 deletions InternetTest/InternetTest/Pages/LocalizeIPPage.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -51,13 +51,25 @@ public LocalizeIPPage()

private async void LocalizeBtn_Click(object sender, RoutedEventArgs e)
{
var ip = await Global.GetIPInfo(IPTxt.Text);
IPInfoTxt.Text = ip.ToString();
var ip = await Global.GetIPInfo(IPTxt.Text); // Get IP info
IPInfoTxt.Text = ip.ToString(); // Show IP info

if (string.IsNullOrEmpty(IPTxt.Text))
{
IPTxt.Text = ip.Query;
}
}

private void OpenMapBtn_Click(object sender, RoutedEventArgs e)
{

}

private async void MyIPBtn_Click(object sender, RoutedEventArgs e)
{
var ip = await Global.GetIPInfo(""); // Get IP info
IPInfoTxt.Text = ip.ToString(); // Show IP info
IPTxt.Text = ip.Query;
}
}
}

0 comments on commit 9851a2e

Please sign in to comment.