Browse Source

commit: add GetMyIP

HOME 4 years ago
parent
commit
7cf2aacc50
8 changed files with 272 additions and 3 deletions
  1. 1 1
      D3NsCore/D3NsClient.cs
  2. 19 2
      DirectDDNS.sln
  3. 26 0
      MyIP/IpModule.cs
  4. 111 0
      MyIP/MyIP.csproj
  5. 35 0
      MyIP/Properties/AssemblyInfo.cs
  6. 31 0
      MyIP/Web.Debug.config
  7. 32 0
      MyIP/Web.Release.config
  8. 17 0
      MyIP/Web.config

+ 1 - 1
D3NsCore/D3NsClient.cs

@@ -94,7 +94,7 @@ namespace D3NsCore
 
         // ---- utilitys ----
 
-        private string GetMyIp() => _http.GetJsonAnon(new { REMOTE_ADDR = "" }, _conf.GetMyIp).REMOTE_ADDR;
+        private string GetMyIp() => _http.GetString(_conf.GetMyIp);
 
         private string GetDnsIp() => _http.GetJsonAnon(new[] { new { data = "" } }, $"https://api.godaddy.com/v1/domains/{_conf.Domain}/records/A/{_conf.DnsRecordName}", new HttpHeader("Accept", "application/json"), new HttpHeader("Authorization", $"sso-key {_conf.Key}:{_conf.Secret}")).Select(p => p.data).Single();
 

+ 19 - 2
DirectDDNS.sln

@@ -1,22 +1,39 @@
 
 Microsoft Visual Studio Solution File, Format Version 12.00
-# Visual Studio 15
-VisualStudioVersion = 15.0.26430.14
+# Visual Studio Version 16
+VisualStudioVersion = 16.0.29728.190
 MinimumVisualStudioVersion = 10.0.40219.1
 Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "D3NsCore", "D3NsCore\D3NsCore.csproj", "{770B76D8-F319-47EE-BF90-5D434DD07CA1}"
 EndProject
+Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "MyIP", "MyIP\MyIP.csproj", "{6A6DBA43-F57E-47C7-9102-E02C91E5747E}"
+EndProject
 Global
 	GlobalSection(SolutionConfigurationPlatforms) = preSolution
+		Debug|Any CPU = Debug|Any CPU
 		Debug|x64 = Debug|x64
+		Release|Any CPU = Release|Any CPU
 		Release|x64 = Release|x64
 	EndGlobalSection
 	GlobalSection(ProjectConfigurationPlatforms) = postSolution
+		{770B76D8-F319-47EE-BF90-5D434DD07CA1}.Debug|Any CPU.ActiveCfg = Debug|x64
 		{770B76D8-F319-47EE-BF90-5D434DD07CA1}.Debug|x64.ActiveCfg = Debug|x64
 		{770B76D8-F319-47EE-BF90-5D434DD07CA1}.Debug|x64.Build.0 = Debug|x64
+		{770B76D8-F319-47EE-BF90-5D434DD07CA1}.Release|Any CPU.ActiveCfg = Release|x64
 		{770B76D8-F319-47EE-BF90-5D434DD07CA1}.Release|x64.ActiveCfg = Release|x64
 		{770B76D8-F319-47EE-BF90-5D434DD07CA1}.Release|x64.Build.0 = Release|x64
+		{6A6DBA43-F57E-47C7-9102-E02C91E5747E}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
+		{6A6DBA43-F57E-47C7-9102-E02C91E5747E}.Debug|Any CPU.Build.0 = Debug|Any CPU
+		{6A6DBA43-F57E-47C7-9102-E02C91E5747E}.Debug|x64.ActiveCfg = Debug|Any CPU
+		{6A6DBA43-F57E-47C7-9102-E02C91E5747E}.Debug|x64.Build.0 = Debug|Any CPU
+		{6A6DBA43-F57E-47C7-9102-E02C91E5747E}.Release|Any CPU.ActiveCfg = Release|Any CPU
+		{6A6DBA43-F57E-47C7-9102-E02C91E5747E}.Release|Any CPU.Build.0 = Release|Any CPU
+		{6A6DBA43-F57E-47C7-9102-E02C91E5747E}.Release|x64.ActiveCfg = Release|Any CPU
+		{6A6DBA43-F57E-47C7-9102-E02C91E5747E}.Release|x64.Build.0 = Release|Any CPU
 	EndGlobalSection
 	GlobalSection(SolutionProperties) = preSolution
 		HideSolutionNode = FALSE
 	EndGlobalSection
+	GlobalSection(ExtensibilityGlobals) = postSolution
+		SolutionGuid = {2DC8A2D3-DB94-42CB-BE3F-83014BFA74F6}
+	EndGlobalSection
 EndGlobal

+ 26 - 0
MyIP/IpModule.cs

@@ -0,0 +1,26 @@
+using System;
+using System.Web;
+
+namespace MyIP
+{
+    public class IpModule : IHttpModule
+    {
+        public void Init(HttpApplication context)
+        {
+            context.BeginRequest += Context_BeginRequest;
+        }
+
+        private void Context_BeginRequest(object sender, EventArgs e)
+        {
+            var context = HttpContext.Current;
+            var userHostAddress = context.Request.UserHostAddress;
+            context.Response.ContentType = "text/ip-address";
+            context.Response.Write(userHostAddress);
+            context.ApplicationInstance.CompleteRequest();
+        }
+
+        public void Dispose()
+        {
+        }
+    }
+}

+ 111 - 0
MyIP/MyIP.csproj

@@ -0,0 +1,111 @@
+<Project ToolsVersion="15.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>
+    <ProductVersion>
+    </ProductVersion>
+    <SchemaVersion>2.0</SchemaVersion>
+    <ProjectGuid>{6A6DBA43-F57E-47C7-9102-E02C91E5747E}</ProjectGuid>
+    <ProjectTypeGuids>{349c5851-65df-11da-9384-00065b846f21};{fae04ec0-301f-11d3-bf4b-00c04f79efbc}</ProjectTypeGuids>
+    <OutputType>Library</OutputType>
+    <AppDesignerFolder>Properties</AppDesignerFolder>
+    <RootNamespace>MyIP</RootNamespace>
+    <AssemblyName>MyIP</AssemblyName>
+    <TargetFrameworkVersion>v4.6.1</TargetFrameworkVersion>
+    <UseIISExpress>true</UseIISExpress>
+    <Use64BitIISExpress />
+    <IISExpressSSLPort />
+    <IISExpressAnonymousAuthentication />
+    <IISExpressWindowsAuthentication />
+    <IISExpressUseClassicPipelineMode />
+    <UseGlobalApplicationHostFile />
+    <NuGetPackageImportStamp>
+    </NuGetPackageImportStamp>
+  </PropertyGroup>
+  <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
+    <DebugSymbols>true</DebugSymbols>
+    <DebugType>full</DebugType>
+    <Optimize>false</Optimize>
+    <OutputPath>bin\</OutputPath>
+    <DefineConstants>DEBUG;TRACE</DefineConstants>
+    <ErrorReport>prompt</ErrorReport>
+    <WarningLevel>4</WarningLevel>
+  </PropertyGroup>
+  <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
+    <DebugSymbols>true</DebugSymbols>
+    <DebugType>pdbonly</DebugType>
+    <Optimize>true</Optimize>
+    <OutputPath>bin\</OutputPath>
+    <DefineConstants>TRACE</DefineConstants>
+    <ErrorReport>prompt</ErrorReport>
+    <WarningLevel>4</WarningLevel>
+  </PropertyGroup>
+  <ItemGroup>
+    <Reference Include="Microsoft.CSharp" />
+    <Reference Include="System.Web.DynamicData" />
+    <Reference Include="System.Web.Entity" />
+    <Reference Include="System.Web.ApplicationServices" />
+    <Reference Include="System.ComponentModel.DataAnnotations" />
+    <Reference Include="System" />
+    <Reference Include="System.Data" />
+    <Reference Include="System.Core" />
+    <Reference Include="System.Data.DataSetExtensions" />
+    <Reference Include="System.Web.Extensions" />
+    <Reference Include="System.Xml.Linq" />
+    <Reference Include="System.Drawing" />
+    <Reference Include="System.Web" />
+    <Reference Include="System.Xml" />
+    <Reference Include="System.Configuration" />
+    <Reference Include="System.Web.Services" />
+    <Reference Include="System.EnterpriseServices" />
+  </ItemGroup>
+  <ItemGroup>
+    <Content Include="Web.config" />
+  </ItemGroup>
+  <ItemGroup>
+    <Compile Include="IpModule.cs" />
+    <Compile Include="Properties\AssemblyInfo.cs" />
+  </ItemGroup>
+  <ItemGroup>
+    <None Include="Properties\PublishProfiles\FolderProfile.pubxml" />
+    <None Include="Web.Debug.config">
+      <DependentUpon>Web.config</DependentUpon>
+    </None>
+    <None Include="Web.Release.config">
+      <DependentUpon>Web.config</DependentUpon>
+    </None>
+  </ItemGroup>
+  <PropertyGroup>
+    <VisualStudioVersion Condition="'$(VisualStudioVersion)' == ''">10.0</VisualStudioVersion>
+    <VSToolsPath Condition="'$(VSToolsPath)' == ''">$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)</VSToolsPath>
+  </PropertyGroup>
+  <Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
+  <Import Project="$(VSToolsPath)\WebApplications\Microsoft.WebApplication.targets" Condition="'$(VSToolsPath)' != ''" />
+  <Import Project="$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v10.0\WebApplications\Microsoft.WebApplication.targets" Condition="false" />
+  <ProjectExtensions>
+    <VisualStudio>
+      <FlavorProperties GUID="{349c5851-65df-11da-9384-00065b846f21}">
+        <WebProjectProperties>
+          <UseIIS>True</UseIIS>
+          <AutoAssignPort>True</AutoAssignPort>
+          <DevelopmentServerPort>53833</DevelopmentServerPort>
+          <DevelopmentServerVPath>/</DevelopmentServerVPath>
+          <IISUrl>http://localhost:53833/</IISUrl>
+          <NTLMAuthentication>False</NTLMAuthentication>
+          <UseCustomServer>False</UseCustomServer>
+          <CustomServerUrl>
+          </CustomServerUrl>
+          <SaveServerSettingsInUserFile>False</SaveServerSettingsInUserFile>
+        </WebProjectProperties>
+      </FlavorProperties>
+    </VisualStudio>
+  </ProjectExtensions>
+  <!-- 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>

+ 35 - 0
MyIP/Properties/AssemblyInfo.cs

@@ -0,0 +1,35 @@
+using System.Reflection;
+using System.Runtime.CompilerServices;
+using System.Runtime.InteropServices;
+
+// 有关程序集的常规信息通过下列特性集
+// 控制。更改这些特性值可修改
+// 与程序集关联的信息。
+[assembly: AssemblyTitle("MyIP")]
+[assembly: AssemblyDescription("")]
+[assembly: AssemblyConfiguration("")]
+[assembly: AssemblyCompany("")]
+[assembly: AssemblyProduct("MyIP")]
+[assembly: AssemblyCopyright("Copyright ©  2020")]
+[assembly: AssemblyTrademark("")]
+[assembly: AssemblyCulture("")]
+
+// 将 ComVisible 设置为 false 会使此程序集中的类型
+// 对 COM 组件不可见。如果需要
+// 从 COM 访问此程序集中的某个类型,请针对该类型将 ComVisible 特性设置为 true。
+[assembly: ComVisible(false)]
+
+// 如果此项目向 COM 公开,则下列 GUID 用于 typelib 的 ID
+[assembly: Guid("6a6dba43-f57e-47c7-9102-e02c91e5747e")]
+
+// 程序集的版本信息由下列四个值组成:
+//
+//      主版本
+//      次版本
+//      内部版本号
+//      修订版本
+//
+// 可以指定所有值,也可以使用“修订号”和“内部版本号”的默认值,
+// 方法是按如下所示使用 "*":
+[assembly: AssemblyVersion("1.0.0.0")]
+[assembly: AssemblyFileVersion("1.0.0.0")]

+ 31 - 0
MyIP/Web.Debug.config

@@ -0,0 +1,31 @@
+<?xml version="1.0" encoding="utf-8"?>
+
+<!-- 有关使用 web.config 转换的详细信息,请访问 https://go.microsoft.com/fwlink/?LinkId=125889 -->
+
+<configuration xmlns:xdt="http://schemas.microsoft.com/XML-Document-Transform">
+  <!--
+    在下例中,“SetAttributes”转换将更改 
+    “connectionString”的值,以仅在“Match”定位器 
+    找到值为“MyDB”的特性“name”时使用“ReleaseSQLServer”。
+    
+    <connectionStrings>
+      <add name="MyDB" 
+        connectionString="Data Source=ReleaseSQLServer;Initial Catalog=MyReleaseDB;Integrated Security=True" 
+        xdt:Transform="SetAttributes" xdt:Locator="Match(name)"/>
+    </connectionStrings>
+  -->
+  <system.web>
+    <!--
+      
+      在下例中,“Replace”转换将替换 
+      web.config 文件的整个 <customErrors> 节。
+      请注意,由于 
+      在 <system.web> 节点下仅有一个 customErrors 节,因此不需要使用“xdt:Locator”特性。
+      
+      <customErrors defaultRedirect="GenericError.htm"
+        mode="RemoteOnly" xdt:Transform="Replace">
+        <error statusCode="500" redirect="InternalError.htm"/>
+      </customErrors>
+    -->
+  </system.web>
+</configuration>

+ 32 - 0
MyIP/Web.Release.config

@@ -0,0 +1,32 @@
+<?xml version="1.0" encoding="utf-8"?>
+
+<!-- 有关使用 web.config 转换的详细信息,请访问 https://go.microsoft.com/fwlink/?LinkId=125889 -->
+
+<configuration xmlns:xdt="http://schemas.microsoft.com/XML-Document-Transform">
+  <!--
+    在下例中,“SetAttributes”转换将更改 
+    “connectionString”的值,以仅在“Match”定位器 
+    找到值为“MyDB”的特性“name”时使用“ReleaseSQLServer”。
+    
+    <connectionStrings>
+      <add name="MyDB" 
+        connectionString="Data Source=ReleaseSQLServer;Initial Catalog=MyReleaseDB;Integrated Security=True" 
+        xdt:Transform="SetAttributes" xdt:Locator="Match(name)"/>
+    </connectionStrings>
+  -->
+  <system.web>
+    <compilation xdt:Transform="RemoveAttributes(debug)" />
+    <!--
+      
+      在下例中,“Replace”转换将替换 
+      web.config 文件的整个 <customErrors> 节。
+      请注意,由于 
+      在 <system.web> 节点下仅有一个 customErrors 节,因此不需要使用“xdt:Locator”特性。
+      
+      <customErrors defaultRedirect="GenericError.htm"
+        mode="RemoteOnly" xdt:Transform="Replace">
+        <error statusCode="500" redirect="InternalError.htm"/>
+      </customErrors>
+    -->
+  </system.web>
+</configuration>

+ 17 - 0
MyIP/Web.config

@@ -0,0 +1,17 @@
+<?xml version="1.0" encoding="utf-8"?>
+
+<!--
+  有关如何配置 ASP.NET 应用程序的详细信息,请访问
+  https://go.microsoft.com/fwlink/?LinkId=169433
+-->
+<configuration>
+  <system.web>
+    <compilation debug="true" targetFramework="4.6.1" />
+    <httpRuntime targetFramework="4.6.1" />
+  </system.web>
+  <system.webServer>
+    <modules>
+      <add name="IpModule" type="MyIP.IpModule" />
+    </modules>
+  </system.webServer>
+</configuration>