Last active
August 29, 2015 13:56
-
-
Save daramkun/9116612 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
| 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