diff --git a/App.config b/App.config index 8c62091..4944e46 100644 --- a/App.config +++ b/App.config @@ -7,6 +7,9 @@ + + + diff --git a/IPMonitor.csproj b/IPMonitor.csproj index fd955d1..9d498fb 100644 --- a/IPMonitor.csproj +++ b/IPMonitor.csproj @@ -37,6 +37,8 @@ + + @@ -44,13 +46,17 @@ + + + + diff --git a/IPMonitor.v12.suo b/IPMonitor.v12.suo index 5c42ff7..2c88057 100644 Binary files a/IPMonitor.v12.suo and b/IPMonitor.v12.suo differ diff --git a/Program.cs b/Program.cs index a4d20ab..2cdfde1 100644 --- a/Program.cs +++ b/Program.cs @@ -5,42 +5,51 @@ using System.Text; using System.Threading.Tasks; using System.Configuration; using System.Net; +using System.Net.Http; using System.IO; using System.Diagnostics; using System.Threading; +using System.Web; namespace IPMonitor { class Program { - //public static String GetPublicIPAddress() - //{ - // try - // { - // String address = ""; - // WebRequest request = WebRequest.Create("http://checkip.dyndns.org/"); - // using (WebResponse response = request.GetResponse()) - // using (StreamReader stream = new StreamReader(response.GetResponseStream())) - // { - // address = stream.ReadToEnd(); - // } - - // int first = address.IndexOf("Address: ") + 9; - // int last = address.LastIndexOf(""); - // address = address.Substring(first, last - first); - - // return address; - // } - // catch(Exception exception) - // { - // String message = String.Format("[IPMonitor::GetPublicIPAddress] Exception:{0}",exception.ToString()); - // MDTrace.WriteLine(LogLevel.DEBUG,message); - // SendSMSEmail("IPMonitor encountered an issue retrieving."); - // return null; - // } - //} +// Main + public static void UpdateIPAddress(String ipAddress) + { + try + { + String strPathFileName="ipaddress.txt"; + if(!File.Exists(strPathFileName)) + { + WriteFile(strPathFileName, ipAddress); + ZoneEditResponses zoneEditResponses=UpdateZoneEditRecord(ipAddress); + SendSMSEmail(String.Format("IPMonitor IPAddress {0}. ZoneEditUpdated={1}",ipAddress,zoneEditResponses.IsSuccess())); + } + else + { + String currentIPAddress=ReadFile(strPathFileName); + if(null!=currentIPAddress && !currentIPAddress.Equals(ipAddress)) + { + WriteFile(strPathFileName,ipAddress); + ZoneEditResponses zoneEditResponses=UpdateZoneEditRecord(ipAddress); + SendSMSEmail(String.Format("IPMonitor IPAddress {0}. ZoneEditUpdated={1}",ipAddress,zoneEditResponses.IsSuccess())); + } + else if(null==currentIPAddress) + { + SendSMSEmail("IPMonitor "+ipAddress+ ". IPMonitor encountered an issue reading the IPAddress file."); + } + } + } + catch(Exception exception) + { + MDTrace.WriteLine(LogLevel.DEBUG,String.Format("[IPMonitor::UpdateIPAddress] Exception:{0}",exception.ToString())); + } + } + public static String GetPublicIPAddress() { int MAX_RETRIES=5; @@ -92,34 +101,33 @@ namespace IPMonitor } } - public static void UpdateIPAddress(String ipAddress) + public static ZoneEditResponses UpdateZoneEditRecord(String ipAddress) { - try + HttpClient client = new HttpClient(); + + String user=ConfigurationManager.AppSettings["zoneedit_user"]; + String password=ConfigurationManager.AppSettings["zoneedit_password"]; + String host=ConfigurationManager.AppSettings["zoneedit_host"]; + + String strRequest=null; + StringBuilder sb=new StringBuilder(); + HttpNetResponse httpNetResponse=null; + + sb = new StringBuilder(); + sb.Append("https://"); + sb.Append("dynamic.zoneedit.com/auth/dynamic.html"); + sb.Append("?host=").Append(HttpUtility.UrlEncode(host)); + sb.Append("&dnsto=").Append(HttpUtility.UrlEncode(ipAddress)); + strRequest=sb.ToString(); + httpNetResponse = HttpNetRequest.GetRequestNoEncodingV5C(strRequest,user,password); + + if(!httpNetResponse.Success) { - String strPathFileName="ipaddress.txt"; - if(!File.Exists(strPathFileName)) - { - WriteFile(strPathFileName, ipAddress); - SendSMSEmail(String.Format("IPMonitor IPAddress {0}",ipAddress)); - } - else - { - String currentIPAddress=ReadFile(strPathFileName); - if(null!=currentIPAddress && !currentIPAddress.Equals(ipAddress)) - { - WriteFile(strPathFileName,ipAddress); - SendSMSEmail(String.Format("IPMonitor IPAddress {0}",ipAddress)); - } - else if(null==currentIPAddress) - { - SendSMSEmail("IPMonitor "+ipAddress+ ". IPMonitor encountered an issue reading the IPAddress file."); - } - } - } - catch(Exception exception) - { - MDTrace.WriteLine(LogLevel.DEBUG,String.Format("[IPMonitor::UpdateIPAddress] Exception:{0}",exception.ToString())); + return new ZoneEditResponses(); } + + MDTrace.WriteLine(LogLevel.DEBUG,String.Format("{0}",httpNetResponse.ResponseString)); + return new ZoneEditResponses(httpNetResponse.ResponseString); } public static void WriteFile(String strPathFileName,String ipAddress) diff --git a/bin/Debug/IPMonitor.exe b/bin/Debug/IPMonitor.exe index 21afd64..d562396 100644 Binary files a/bin/Debug/IPMonitor.exe and b/bin/Debug/IPMonitor.exe differ diff --git a/bin/Debug/IPMonitor.exe.config b/bin/Debug/IPMonitor.exe.config index 8c62091..4944e46 100644 --- a/bin/Debug/IPMonitor.exe.config +++ b/bin/Debug/IPMonitor.exe.config @@ -7,6 +7,9 @@ + + + diff --git a/bin/Debug/IPMonitor.pdb b/bin/Debug/IPMonitor.pdb index 87056e4..0652e09 100644 Binary files a/bin/Debug/IPMonitor.pdb and b/bin/Debug/IPMonitor.pdb differ diff --git a/bin/Debug/IPMonitor.vshost.exe.config b/bin/Debug/IPMonitor.vshost.exe.config index ee8d2ae..8c62091 100644 --- a/bin/Debug/IPMonitor.vshost.exe.config +++ b/bin/Debug/IPMonitor.vshost.exe.config @@ -2,7 +2,7 @@ - + diff --git a/bin/Release/IPMonitor.exe b/bin/Release/IPMonitor.exe index 21afd64..d562396 100644 Binary files a/bin/Release/IPMonitor.exe and b/bin/Release/IPMonitor.exe differ diff --git a/bin/Release/IPMonitor.exe.config b/bin/Release/IPMonitor.exe.config index 8c62091..4944e46 100644 --- a/bin/Release/IPMonitor.exe.config +++ b/bin/Release/IPMonitor.exe.config @@ -7,6 +7,9 @@ + + + diff --git a/bin/Release/IPMonitor.pdb b/bin/Release/IPMonitor.pdb index 87056e4..0652e09 100644 Binary files a/bin/Release/IPMonitor.pdb and b/bin/Release/IPMonitor.pdb differ diff --git a/bin/Release/IPMonitor.vshost.exe.config b/bin/Release/IPMonitor.vshost.exe.config index 06058de..8c62091 100644 --- a/bin/Release/IPMonitor.vshost.exe.config +++ b/bin/Release/IPMonitor.vshost.exe.config @@ -2,6 +2,7 @@ + diff --git a/bin/Release/ipmonitor.log b/bin/Release/ipmonitor.log index 16b853a..3a6f37c 100644 --- a/bin/Release/ipmonitor.log +++ b/bin/Release/ipmonitor.log @@ -1,5 +1,5 @@ -[LOCAL][Thread=1][TRACE.DEBUG][3/14/2024 7:08:13 AM] [IPMonitor.Program::Main(args)][IPMonitor::Start] C:\boneyard\IPMonitor\bin\Release -[LOCAL][Thread=1][TRACE.DEBUG][3/14/2024 10:18:48 AM] [IPMonitor.Program::GetHttpRequest(strRequest)][IPMonitor:GetHttpRequest] failed with System.Net.WebException: The remote server returned an error: (502) Bad Gateway. - at System.Net.HttpWebRequest.GetResponse() - at IPMonitor.Program.GetHttpRequest(String strRequest) in c:\boneyard\IPMonitor\Program.cs:line 82 -[LOCAL][Thread=1][TRACE.DEBUG][3/14/2024 10:18:48 AM] [IPMonitor.Program::GetPublicIPAddress()][IPMonitor::GetPublicIPAddress] Request failed http://checkip.dyndns.org/. Will retry after 30000 (ms) +[LOCAL][Thread=1][TRACE.DEBUG][3/17/2024 11:14:08 AM] [IPMonitor.Program::Main(args)][IPMonitor::Start] C:\boneyard\IPMonitor\bin\Release +[LOCAL][Thread=1][TRACE.DEBUG][3/17/2024 11:14:10 AM] [IPMonitor.Program::WriteFile(strPathFileName,ipAddress)]Creating address file:ipaddress.txt +[LOCAL][Thread=1][TRACE.DEBUG][3/17/2024 11:14:14 AM] [IPMonitor.Program::UpdateZoneEditRecord(ipAddress)] + + diff --git a/obj/Debug/DesignTimeResolveAssemblyReferencesInput.cache b/obj/Debug/DesignTimeResolveAssemblyReferencesInput.cache index 1dfb5e8..d84488d 100644 Binary files a/obj/Debug/DesignTimeResolveAssemblyReferencesInput.cache and b/obj/Debug/DesignTimeResolveAssemblyReferencesInput.cache differ diff --git a/obj/Debug/IPMonitor.csproj.FileListAbsolute.txt b/obj/Debug/IPMonitor.csproj.FileListAbsolute.txt index 2d4dc05..5f529ac 100644 --- a/obj/Debug/IPMonitor.csproj.FileListAbsolute.txt +++ b/obj/Debug/IPMonitor.csproj.FileListAbsolute.txt @@ -9,3 +9,4 @@ C:\boneyard\IPMonitor\bin\Debug\IPMonitor.exe C:\boneyard\IPMonitor\bin\Debug\IPMonitor.pdb C:\boneyard\IPMonitor\obj\Debug\IPMonitor.exe C:\boneyard\IPMonitor\obj\Debug\IPMonitor.pdb +C:\boneyard\IPMonitor\obj\Debug\IPMonitor.csprojResolveAssemblyReference.cache diff --git a/obj/Debug/IPMonitor.exe b/obj/Debug/IPMonitor.exe index 21afd64..d562396 100644 Binary files a/obj/Debug/IPMonitor.exe and b/obj/Debug/IPMonitor.exe differ diff --git a/obj/Debug/IPMonitor.pdb b/obj/Debug/IPMonitor.pdb index 87056e4..0652e09 100644 Binary files a/obj/Debug/IPMonitor.pdb and b/obj/Debug/IPMonitor.pdb differ