-
Notifications
You must be signed in to change notification settings - Fork 7
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
13 changed files
with
417 additions
and
0 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 |
---|---|---|
@@ -0,0 +1,16 @@ | ||
/* | ||
Copyright © 2015 David Musgrove. | ||
Licensed under the terms of the MIT License. | ||
*/ | ||
|
||
using System.Reflection; | ||
|
||
[assembly: AssemblyCompany("David Musgrove")] | ||
[assembly: AssemblyProduct("Ipify")] | ||
[assembly: AssemblyCopyright("Copyright © 2015 David Musgrove")] | ||
[assembly: AssemblyVersion("1.0.0.0")] | ||
#if DEBUG | ||
[assembly: AssemblyConfiguration("Debug")] | ||
#else | ||
[assembly: AssemblyConfiguration("Release")] | ||
#endif |
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,68 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<Project ToolsVersion="14.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> | ||
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" /> | ||
<PropertyGroup> | ||
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration> | ||
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform> | ||
<ProjectGuid>{A5A12BA3-3E1D-4B2D-BDCC-930A29836244}</ProjectGuid> | ||
<OutputType>Library</OutputType> | ||
<AppDesignerFolder>Properties</AppDesignerFolder> | ||
<RootNamespace>Ipify.Tests</RootNamespace> | ||
<AssemblyName>Ipify.Tests</AssemblyName> | ||
<TargetFrameworkVersion>v3.5</TargetFrameworkVersion> | ||
<FileAlignment>512</FileAlignment> | ||
<TargetFrameworkProfile /> | ||
</PropertyGroup> | ||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' "> | ||
<DebugSymbols>true</DebugSymbols> | ||
<DebugType>full</DebugType> | ||
<Optimize>false</Optimize> | ||
<OutputPath>bin\Debug\</OutputPath> | ||
<DefineConstants>DEBUG;TRACE</DefineConstants> | ||
<ErrorReport>prompt</ErrorReport> | ||
<WarningLevel>4</WarningLevel> | ||
<TreatWarningsAsErrors>true</TreatWarningsAsErrors> | ||
</PropertyGroup> | ||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' "> | ||
<DebugType>pdbonly</DebugType> | ||
<Optimize>true</Optimize> | ||
<OutputPath>bin\Release\</OutputPath> | ||
<DefineConstants>TRACE</DefineConstants> | ||
<ErrorReport>prompt</ErrorReport> | ||
<WarningLevel>4</WarningLevel> | ||
<TreatWarningsAsErrors>true</TreatWarningsAsErrors> | ||
<DocumentationFile> | ||
</DocumentationFile> | ||
</PropertyGroup> | ||
<ItemGroup> | ||
<Reference Include="nunit.framework, Version=2.6.3.13283, Culture=neutral, PublicKeyToken=96d09a1eb7f44a77, processorArchitecture=MSIL"> | ||
<HintPath>..\packages\NUnit.2.6.3\lib\nunit.framework.dll</HintPath> | ||
<Private>True</Private> | ||
</Reference> | ||
<Reference Include="System" /> | ||
</ItemGroup> | ||
<ItemGroup> | ||
<Compile Include="..\GlobalAssemblyInfo.cs"> | ||
<Link>Properties\GlobalAssemblyInfo.cs</Link> | ||
</Compile> | ||
<Compile Include="IpifyTests.cs" /> | ||
<Compile Include="Properties\AssemblyInfo.cs" /> | ||
</ItemGroup> | ||
<ItemGroup> | ||
<None Include="packages.config" /> | ||
</ItemGroup> | ||
<ItemGroup> | ||
<ProjectReference Include="..\Ipify\Ipify.csproj"> | ||
<Project>{3A76ED6C-03A7-4432-9187-CFF0CD97D53E}</Project> | ||
<Name>Ipify</Name> | ||
</ProjectReference> | ||
</ItemGroup> | ||
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" /> | ||
<!-- To modify your build process, add your task inside one of the targets below and uncomment it. | ||
Other similar extension points exist, see Microsoft.Common.targets. | ||
<Target Name="BeforeBuild"> | ||
</Target> | ||
<Target Name="AfterBuild"> | ||
</Target> | ||
--> | ||
</Project> |
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,47 @@ | ||
/* | ||
Copyright © 2015 David Musgrove. | ||
Licensed under the terms of the MIT License. | ||
*/ | ||
|
||
using System.Net; | ||
|
||
using NUnit.Framework; | ||
|
||
namespace Ipify.Tests | ||
{ | ||
[TestFixture] | ||
public class IpifyTests | ||
{ | ||
[Test] | ||
public void GetAddress_ReturnsStringContainingAnIPAddress() | ||
{ | ||
string ip = Ipify.GetPublicAddress(); | ||
IPAddress ipAddress; | ||
Assert.IsTrue(IPAddress.TryParse(ip, out ipAddress)); | ||
} | ||
|
||
[Test] | ||
public void GetAddress_ReturnsStringContainingAnIPAddressUsingHttps() | ||
{ | ||
string ip = Ipify.GetPublicAddress(true); | ||
IPAddress ipAddress; | ||
Assert.IsTrue(IPAddress.TryParse(ip, out ipAddress)); | ||
} | ||
|
||
[Test] | ||
public void GetIPAddress_ReturnsIPAddressInstance() | ||
{ | ||
IPAddress ipAddress = Ipify.GetPublicIPAddress(); | ||
Assert.IsNotNull(ipAddress); | ||
Assert.AreNotEqual(IPAddress.None, ipAddress); | ||
} | ||
|
||
[Test] | ||
public void GetIPAddress_ReturnsIPAddressInstanceUsingHttps() | ||
{ | ||
IPAddress ipAddress = Ipify.GetPublicIPAddress(true); | ||
Assert.IsNotNull(ipAddress); | ||
Assert.AreNotEqual(IPAddress.None, ipAddress); | ||
} | ||
} | ||
} |
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,9 @@ | ||
/* | ||
Copyright © 2015 David Musgrove. | ||
Licensed under the terms of the MIT License. | ||
*/ | ||
|
||
using System.Reflection; | ||
|
||
[assembly: AssemblyTitle("Ipify.Tests")] | ||
[assembly: AssemblyDescription("Unit tets for Ipify.")] |
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,4 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<packages> | ||
<package id="NUnit" version="2.6.3" targetFramework="net452" /> | ||
</packages> |
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,17 @@ | ||
<?xml version="1.0"?> | ||
<package xmlns="http://schemas.microsoft.com/packaging/2010/07/nuspec.xsd"> | ||
<metadata> | ||
<id>Ipify.NET</id> | ||
<version>1.0.0</version> | ||
<authors>David Musgrove</authors> | ||
<requireLicenseAcceptance>true</requireLicenseAcceptance> | ||
<licenseUrl>https://github.com/davidmus/Ipify.NET/blob/master/LICENSE</licenseUrl> | ||
<description> | ||
.NET library to wrap the public IP address resolution service at ipify.org. | ||
</description> | ||
</metadata> | ||
<files> | ||
<file src="Ipify\bin\Release\Ipify.dll" target="lib\net35" /> | ||
<file src="Ipify\bin\Release\Ipify.xml" target="lib\net35" /> | ||
</files> | ||
</package> |
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,65 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003" ToolsVersion="4.0"> | ||
<PropertyGroup> | ||
<!-- The configuration and platform will be used to determine which | ||
assemblies to include from solution and project documentation | ||
sources --> | ||
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration> | ||
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform> | ||
<SchemaVersion>2.0</SchemaVersion> | ||
<ProjectGuid>{3c7d6631-d999-4e76-be64-7550ecdd3907}</ProjectGuid> | ||
<SHFBSchemaVersion>1.9.5.0</SHFBSchemaVersion> | ||
<!-- AssemblyName, Name, and RootNamespace are not used by SHFB but Visual | ||
Studio adds them anyway --> | ||
<AssemblyName>Documentation</AssemblyName> | ||
<RootNamespace>Documentation</RootNamespace> | ||
<Name>Documentation</Name> | ||
<!-- SHFB properties --> | ||
<FrameworkVersion>.NET Framework 3.5</FrameworkVersion> | ||
<OutputPath>..\doc\</OutputPath> | ||
<HtmlHelpName>Documentation</HtmlHelpName> | ||
<Language>en-US</Language> | ||
<DocumentationSources> | ||
<DocumentationSource sourceFile="Ipify\bin\Release\Ipify.dll" /> | ||
<DocumentationSource sourceFile="Ipify\bin\Release\Ipify.xml" /> | ||
</DocumentationSources> | ||
<BuildAssemblerVerbosity>OnlyWarningsAndErrors</BuildAssemblerVerbosity> | ||
<HelpFileFormat>Website</HelpFileFormat> | ||
<IndentHtml>False</IndentHtml> | ||
<KeepLogFile>False</KeepLogFile> | ||
<DisableCodeBlockComponent>False</DisableCodeBlockComponent> | ||
<CppCommentsFixup>False</CppCommentsFixup> | ||
<CleanIntermediates>True</CleanIntermediates> | ||
<SyntaxFilters>Standard</SyntaxFilters> | ||
<SdkLinkTarget>Blank</SdkLinkTarget> | ||
<RootNamespaceContainer>False</RootNamespaceContainer> | ||
<PresentationStyle>VS2010</PresentationStyle> | ||
<Preliminary>False</Preliminary> | ||
<NamingMethod>Guid</NamingMethod> | ||
<HelpTitle>A Sandcastle Documented Class Library</HelpTitle> | ||
<FeedbackEMailAddress>david%40musgroves.us</FeedbackEMailAddress> | ||
<CopyrightText>Copyright &#169%3b 2015 David Musgrove. Licensed under the MIT License.</CopyrightText> | ||
<ContentPlacement>AboveNamespaces</ContentPlacement> | ||
</PropertyGroup> | ||
<!-- There are no properties for these groups. AnyCPU needs to appear in | ||
order for Visual Studio to perform the build. The others are optional | ||
common platform types that may appear. --> | ||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' "> | ||
</PropertyGroup> | ||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' "> | ||
</PropertyGroup> | ||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|x86' "> | ||
</PropertyGroup> | ||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|x86' "> | ||
</PropertyGroup> | ||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|x64' "> | ||
</PropertyGroup> | ||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|x64' "> | ||
</PropertyGroup> | ||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|Win32' "> | ||
</PropertyGroup> | ||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|Win32' "> | ||
</PropertyGroup> | ||
<!-- Import the SHFB build targets --> | ||
<Import Project="$(SHFBROOT)\SandcastleHelpFileBuilder.targets" /> | ||
</Project> |
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,28 @@ | ||
|
||
Microsoft Visual Studio Solution File, Format Version 12.00 | ||
# Visual Studio 14 | ||
VisualStudioVersion = 14.0.23107.0 | ||
MinimumVisualStudioVersion = 10.0.40219.1 | ||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Ipify", "Ipify\Ipify.csproj", "{3A76ED6C-03A7-4432-9187-CFF0CD97D53E}" | ||
EndProject | ||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Ipify.Tests", "Ipify.Tests\Ipify.Tests.csproj", "{A5A12BA3-3E1D-4B2D-BDCC-930A29836244}" | ||
EndProject | ||
Global | ||
GlobalSection(SolutionConfigurationPlatforms) = preSolution | ||
Debug|Any CPU = Debug|Any CPU | ||
Release|Any CPU = Release|Any CPU | ||
EndGlobalSection | ||
GlobalSection(ProjectConfigurationPlatforms) = postSolution | ||
{3A76ED6C-03A7-4432-9187-CFF0CD97D53E}.Debug|Any CPU.ActiveCfg = Debug|Any CPU | ||
{3A76ED6C-03A7-4432-9187-CFF0CD97D53E}.Debug|Any CPU.Build.0 = Debug|Any CPU | ||
{3A76ED6C-03A7-4432-9187-CFF0CD97D53E}.Release|Any CPU.ActiveCfg = Release|Any CPU | ||
{3A76ED6C-03A7-4432-9187-CFF0CD97D53E}.Release|Any CPU.Build.0 = Release|Any CPU | ||
{A5A12BA3-3E1D-4B2D-BDCC-930A29836244}.Debug|Any CPU.ActiveCfg = Debug|Any CPU | ||
{A5A12BA3-3E1D-4B2D-BDCC-930A29836244}.Debug|Any CPU.Build.0 = Debug|Any CPU | ||
{A5A12BA3-3E1D-4B2D-BDCC-930A29836244}.Release|Any CPU.ActiveCfg = Release|Any CPU | ||
{A5A12BA3-3E1D-4B2D-BDCC-930A29836244}.Release|Any CPU.Build.0 = Release|Any CPU | ||
EndGlobalSection | ||
GlobalSection(SolutionProperties) = preSolution | ||
HideSolutionNode = FALSE | ||
EndGlobalSection | ||
EndGlobal |
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,15 @@ | ||
<wpf:ResourceDictionary xml:space="preserve" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:s="clr-namespace:System;assembly=mscorlib" xmlns:ss="urn:shemas-jetbrains-com:settings-storage-xaml" xmlns:wpf="http://schemas.microsoft.com/winfx/2006/xaml/presentation"> | ||
<s:Int64 x:Key="/Default/CodeStyle/CodeFormatting/CSharpFormat/BLANK_LINES_BETWEEN_USING_GROUPS/@EntryValue">1</s:Int64> | ||
<s:Boolean x:Key="/Default/CodeStyle/CodeFormatting/CSharpFormat/SPACE_AFTER_TYPECAST_PARENTHESES/@EntryValue">False</s:Boolean> | ||
<s:Boolean x:Key="/Default/CodeStyle/CodeFormatting/CSharpFormat/SPACE_AROUND_MULTIPLICATIVE_OP/@EntryValue">True</s:Boolean> | ||
<s:Boolean x:Key="/Default/CodeStyle/CodeFormatting/CSharpFormat/SPACE_BEFORE_SIZEOF_PARENTHESES/@EntryValue">False</s:Boolean> | ||
<s:Boolean x:Key="/Default/CodeStyle/CodeFormatting/CSharpFormat/SPACE_BEFORE_TYPEOF_PARENTHESES/@EntryValue">False</s:Boolean> | ||
<s:String x:Key="/Default/CodeStyle/Naming/CSharpNaming/Abbreviations/=IP/@EntryIndexedValue">IP</s:String> | ||
<s:Boolean x:Key="/Default/Environment/InjectedLayers/FileInjectedLayer/=2C89599149E5714F894CFB1B89EFEEB2/@KeyIndexDefined">True</s:Boolean> | ||
<s:String x:Key="/Default/Environment/InjectedLayers/FileInjectedLayer/=2C89599149E5714F894CFB1B89EFEEB2/AbsolutePath/@EntryValue">C:\workspace\source\Ipify\Ipify.sln.DotSettings</s:String> | ||
<s:String x:Key="/Default/Environment/InjectedLayers/FileInjectedLayer/=2C89599149E5714F894CFB1B89EFEEB2/RelativePath/@EntryValue"></s:String> | ||
<s:Boolean x:Key="/Default/Environment/InjectedLayers/InjectedLayerCustomization/=File2C89599149E5714F894CFB1B89EFEEB2/@KeyIndexDefined">True</s:Boolean> | ||
<s:Double x:Key="/Default/Environment/InjectedLayers/InjectedLayerCustomization/=File2C89599149E5714F894CFB1B89EFEEB2/RelativePriority/@EntryValue">2</s:Double> | ||
<s:Boolean x:Key="/Default/Environment/SettingsMigration/IsMigratorApplied/=JetBrains_002EReSharper_002EPsi_002ECSharp_002ECodeStyle_002ESettingsUpgrade_002EAddAccessorOwnerDeclarationBracesMigration/@EntryIndexedValue">True</s:Boolean> | ||
<s:Boolean x:Key="/Default/Environment/SettingsMigration/IsMigratorApplied/=JetBrains_002EReSharper_002EPsi_002ECSharp_002ECodeStyle_002ESettingsUpgrade_002EMigrateBlankLinesAroundFieldToBlankLinesAroundProperty/@EntryIndexedValue">True</s:Boolean> | ||
<s:Boolean x:Key="/Default/Environment/SettingsMigration/IsMigratorApplied/=JetBrains_002EReSharper_002EPsi_002ECSharp_002ECodeStyle_002ESettingsUpgrade_002EMigrateThisQualifierSettings/@EntryIndexedValue">True</s:Boolean></wpf:ResourceDictionary> |
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,65 @@ | ||
/* | ||
Copyright © 2015 David Musgrove. | ||
Licensed under the terms of the MIT License. | ||
*/ | ||
|
||
using System.Net; | ||
|
||
namespace Ipify | ||
{ | ||
/// <summary> | ||
/// Static utility class exposing methods to facilitate resolving a client's | ||
/// public IP address on the Internet by querying the service at ipify.org. | ||
/// </summary> | ||
public static class Ipify | ||
{ | ||
/// <summary> | ||
/// Resolves the public IP address and returns it as a string. | ||
/// </summary> | ||
/// <param name="useHttps"> | ||
/// Specifies whether to use HTTPS to talk to ipify.org (defaults to | ||
/// <b>false</b> if omitted). | ||
/// </param> | ||
/// <returns> | ||
/// A string containing the IP address, or an empty string if an error is | ||
/// encountered. | ||
/// </returns> | ||
public static string GetPublicAddress(bool useHttps = false) | ||
{ | ||
var endpoint = useHttps ? "https://api.ipify.org" : "http://api.ipify.org"; | ||
WebClient client = new WebClient(); | ||
try | ||
{ | ||
return client.DownloadString(endpoint); | ||
} | ||
catch | ||
{ | ||
return string.Empty; | ||
} | ||
} | ||
|
||
/// <summary> | ||
/// Resolves the public IP address and returns it as an instance of | ||
/// <see cref="IPAddress" />. | ||
/// </summary> | ||
/// <param name="useHttps"> | ||
/// Specifies whether to use HTTPS to talk to ipify.org (defaults to | ||
/// <b>false</b> if omitted). | ||
/// </param> | ||
/// <returns> | ||
/// An instance of <see cref="IPAddress" />. If an error occures, then | ||
/// <see cref="IPAddress.None" /> is returned. | ||
/// encountered. | ||
/// </returns> | ||
public static IPAddress GetPublicIPAddress(bool useHttps = false) | ||
{ | ||
string address = GetPublicAddress(useHttps); | ||
IPAddress ipAddress; | ||
if (!IPAddress.TryParse(address, out ipAddress)) | ||
{ | ||
return IPAddress.None; | ||
} | ||
return ipAddress; | ||
} | ||
} | ||
} |
Oops, something went wrong.