Skip to content

Instantly share code, notes, and snippets.

@daramkun
Last active August 29, 2015 13:56
Show Gist options
  • Select an option

  • Save daramkun/9116612 to your computer and use it in GitHub Desktop.

Select an option

Save daramkun/9116612 to your computer and use it in GitHub Desktop.
using System;
using System.Collections.Generic;
using System.Net;
using System.Net.NetworkInformation;
using System.Text;
using System.Threading;
using System.Windows.Forms;
namespace DdnsUpdater
{
static class Program
{
[STAThread]
static void Main ()
{
Uri url = new Uri ( "http://dyna.dnsever.com/update.php?host[호스트이름]" );
HttpWebRequest req = HttpWebRequest.CreateHttp ( url );
while ( true )
{
if ( !CheckForInternetConnection () ) { Thread.Sleep ( TimeSpan.FromMinutes ( 1 ) ); continue; }
req.PreAuthenticate = true;
req.Credentials = new NetworkCredential ( "사용자ID", "인증코드" ).GetCredential ( url, "Digest" );
req.UserAgent = "DnsEverDDNSUpdater";
try { req.GetResponse ().Dispose (); }
catch { Thread.Sleep ( TimeSpan.FromMinutes ( 1 ) ); continue; }
Thread.Sleep ( TimeSpan.FromHours ( 12 ) );
}
}
public static bool CheckForInternetConnection ()
{
if ( !NetworkInterface.GetIsNetworkAvailable () ) return false;
try
{
using ( var client = new WebClient () )
{
using ( var stream = client.OpenRead ( "http://www.google.com" ) ) { return true; }
}
}
catch { return false; }
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment