Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Text;
- using System.Net;
- using System.Threading;
- namespace RunOnIpChange
- {
- class Program
- {
- static void Main(string[] args)
- {
- string myLastIp = GetMyIp();
- while (true)
- {
- Thread.Sleep(15000);
- string myNewIp = GetMyIp();
- if (myNewIp != myLastIp)
- {
- Console.Write(string.Format("{0}: new IP: {1}", DateTime.Now, myNewIp));
- myLastIp = myNewIp;
- DoStuff();
- }
- else
- {
- Console.Write(string.Format("{0}: IP is still the same: {1}", DateTime.Now, myNewIp));
- }
- }
- }
- private static void DoStuff()
- {
- }
- private static string GetMyIp()
- {
- WebClient wc = new WebClient();
- return wc.DownloadString("http://myexternalip.com/raw");
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement