diff options
| author | Luke Pulverenti <luke.pulverenti@gmail.com> | 2013-12-08 14:39:39 -0500 |
|---|---|---|
| committer | Luke Pulverenti <luke.pulverenti@gmail.com> | 2013-12-08 14:39:39 -0500 |
| commit | f856e166ff1a4d95dc7f8f0656751557c2cd7949 (patch) | |
| tree | 213ed02cd535a2923f0fce632644d750129afc18 /MediaBrowser.ServerApplication/EntryPoints/WanAddressEntryPoint.cs | |
| parent | 803de20bb99e48b55fdf4483042c466bdf844d7a (diff) | |
Add WanAddress to SystemInfo
Diffstat (limited to 'MediaBrowser.ServerApplication/EntryPoints/WanAddressEntryPoint.cs')
| -rw-r--r-- | MediaBrowser.ServerApplication/EntryPoints/WanAddressEntryPoint.cs | 56 |
1 files changed, 56 insertions, 0 deletions
diff --git a/MediaBrowser.ServerApplication/EntryPoints/WanAddressEntryPoint.cs b/MediaBrowser.ServerApplication/EntryPoints/WanAddressEntryPoint.cs new file mode 100644 index 000000000..44819b390 --- /dev/null +++ b/MediaBrowser.ServerApplication/EntryPoints/WanAddressEntryPoint.cs @@ -0,0 +1,56 @@ +using MediaBrowser.Common.Net; +using MediaBrowser.Controller.Plugins; +using System; +using System.IO; +using System.Threading; + +namespace MediaBrowser.ServerApplication.EntryPoints +{ + public class WanAddressEntryPoint : IServerEntryPoint + { + public static string WanAddress; + private Timer _timer; + private readonly IHttpClient _httpClient; + + public WanAddressEntryPoint(IHttpClient httpClient) + { + _httpClient = httpClient; + } + + public void Run() + { + _timer = new Timer(TimerCallback, null, TimeSpan.FromMinutes(1), TimeSpan.FromHours(24)); + } + + private async void TimerCallback(object state) + { + try + { + using (var stream = await _httpClient.Get(new HttpRequestOptions + { + Url = "http://bot.whatismyipaddress.com/" + + }).ConfigureAwait(false)) + { + using (var reader = new StreamReader(stream)) + { + WanAddress = await reader.ReadToEndAsync().ConfigureAwait(false); + } + } + } + catch (Exception ex) + { + var b = true; + } + } + + public void Dispose() + { + if (_timer != null) + { + _timer.Dispose(); + _timer = null; + } + } + } +} |
