ddns automatic refresh via HTTP API

Recommended in this article“ Free DDNS ”For free DDNS service at home, if you have wired commercial bandwidth and have no home bandwidth, you don't need to consider DDNS, unless it is business width, which is DHCP public network IP. Such business width is generally used for illegal trading. There are many people, such as business width, dynamic IP, tut Tut, and the market has a lot of money.

You can refresh through the following HTTP interface. The association between your machine's public network IP and domain name can basically be almost continuous. The home bandwidth PPOPE dial-up authentication can usually be completed within one second. You can call the program automatically and request it every X seconds. The request per second is the best.

https://freemyip.com/update?token = your token & domain = your domain name

You can apply for your free dynamic domain name here

Address: Free DDNS On the official website, enter the domain name prefix you want, and then click check availability to display the following similar prompt. Otherwise, it will prompt "this domain name is not available". This domain name is not available.

https://freemyip.com/update?token=c3f0eaf65e83c5e32bc1ab30&domain=a6666.freemyip.com

For the example domain name I applied for, call the following interface on your local machine to set your public IP as the binding address of the domain name. Of course, because it is a test domain name, many people may call this interface. It may be messy at that time. Just test it.

Retrieve DDNS bundled IP Demo:

nslookup a6666.freemyip.com

The result should now be: 13.73. * *, The address is American · West · California · San Francisco · Santa Clara, but you refreshed a6666 by calling the above interface freemyip. COM, then it may not be.

Run the DDNS automatic refresh program provided in this article

ddns clock cycle call address

cls
ddns.exe 10 "https://freemyip.com/update?token=c3f0eaf65e83c5e32bc1ab30&domain=a6666.freemyip.com"

ddns.cs source code compilation (. C# language compiler provided by NET v4.0.30319)

C:\Windows\Microsoft.NET\Framework\v4.0.30319\csc 
/out:ddns.exe /target:exe /unsafe ddns.cs

One thing to note: compile DDNS The file directory of CS is under the current directory according to the above command, including the output DDNS Exe file is also in the current directory.  

ddns.cs source file implementation

namespace ddns
{
    using System;
    using System.Net;
    using System.Security;
    using System.Threading;

    public unsafe static class Program
    {
        private static void HttpGet(string openUrl)
        {
            using (WebClient wc = new WebClient())
            {
                DateTime b = DateTime.Now;
                try
                {
                    string r = (wc.DownloadString(openUrl) ?? string.Empty).Trim();
                    Console.WriteLine("[{0}][{1}] {2}", b.ToString("yyyy-MM-dd HH:mm:ss"),
                        ((int)(DateTime.Now - b).TotalMilliseconds).ToString("d4"), r);
                }
                catch (Exception)
                {
                    Console.WriteLine("[{0}][{1}] ERROR", b.ToString("yyyy - MM - dd HH: mm:ss"),
                        ((int)(DateTime.Now - b).TotalMilliseconds).ToString("d4"));
                }
            }
        }

        [MTAThread]
        private static void Main(string[] args)
        {
            Console.Title = "DDNS@localhost";
            InitialSecurityProtocol();
            int sleepTime = 1000 * int.Parse(args[0]);
            string openUrl = args[1];
            while (true)
            {
                HttpGet(openUrl);
                Thread.Sleep(sleepTime);
            }
        }

        [SecurityCritical]
        [SecuritySafeCritical]
        private static void InitialSecurityProtocol()
        {
            try
            {
                ServicePointManager.SecurityProtocol = SecurityProtocolType.Ssl3
                                              | SecurityProtocolType.Tls
                                              | (SecurityProtocolType)0x300 // Tls11
                                              | (SecurityProtocolType)0xC00 // Tls12
                                              | (SecurityProtocolType)0x3000; // Tls13
            }
            catch (Exception)
            {
                try
                {
                    ServicePointManager.SecurityProtocol = SecurityProtocolType.Ssl3
                                                  | SecurityProtocolType.Tls
                                                  | (SecurityProtocolType)0x300 // Tls11
                                                  | (SecurityProtocolType)0xC00; // Tls12
                }
                catch (Exception)
                {
                    try
                    {
                        ServicePointManager.SecurityProtocol = SecurityProtocolType.Ssl3
                                                        | SecurityProtocolType.Tls
                                                        | (SecurityProtocolType)0x300; // Tls11
                    }
                    catch (Exception)
                    {
                        try
                        {
                            ServicePointManager.SecurityProtocol = SecurityProtocolType.Ssl3
                                                            | SecurityProtocolType.Tls;
                        }
                        catch (Exception) { }
                    }
                }
            }
        }
    }
}

Keywords: C# network Network Protocol http

Added by nenena on Fri, 25 Feb 2022 05:53:40 +0200