diff options
Diffstat (limited to 'MediaBrowser.Server.Implementations/EntryPoints/WanAddressEntryPoint.cs')
| -rw-r--r-- | MediaBrowser.Server.Implementations/EntryPoints/WanAddressEntryPoint.cs | 55 |
1 files changed, 55 insertions, 0 deletions
diff --git a/MediaBrowser.Server.Implementations/EntryPoints/WanAddressEntryPoint.cs b/MediaBrowser.Server.Implementations/EntryPoints/WanAddressEntryPoint.cs new file mode 100644 index 000000000..2f6643588 --- /dev/null +++ b/MediaBrowser.Server.Implementations/EntryPoints/WanAddressEntryPoint.cs @@ -0,0 +1,55 @@ +using MediaBrowser.Common.Net; +using MediaBrowser.Controller.Plugins; +using System; +using System.IO; +using System.Threading; + +namespace MediaBrowser.Server.Implementations.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 + { + } + } + + public void Dispose() + { + if (_timer != null) + { + _timer.Dispose(); + _timer = null; + } + } + } +} |
