Add ZoneEdit Update.

This commit is contained in:
2024-03-17 11:23:28 -04:00
parent 5dfe2842ff
commit 6ac738e5f3
17 changed files with 82 additions and 57 deletions

View File

@@ -7,6 +7,9 @@
<add key="sms_smsusername" value="skessler1964@gmail.com"/>
<add key="sms_smspassword" value="xjfo isnf gmyi zovr"/>
<add key="sms_smsrecipients" value="skessler1964sms@gmail.com"/>
<add key="zoneedit_user" value="skessler1964"/>
<add key="zoneedit_password" value="4A536A7920309A11"/>
<add key="zoneedit_host" value="diversified-software.com"/>
</appSettings>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.6.2"/>

View File

@@ -37,6 +37,8 @@
<Reference Include="System" />
<Reference Include="System.Configuration" />
<Reference Include="System.Core" />
<Reference Include="System.Net.Http" />
<Reference Include="System.Web" />
<Reference Include="System.Xml.Linq" />
<Reference Include="System.Data.DataSetExtensions" />
<Reference Include="Microsoft.CSharp" />
@@ -44,13 +46,17 @@
<Reference Include="System.Xml" />
</ItemGroup>
<ItemGroup>
<Compile Include="HttpNetRequest.cs" />
<Compile Include="MDTrace.cs" />
<Compile Include="Network.cs" />
<Compile Include="Profiler.cs" />
<Compile Include="Program.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="SMSClient.cs" />
<Compile Include="Socket.cs" />
<Compile Include="UserAgent.cs" />
<Compile Include="Utility.cs" />
<Compile Include="ZoneEditResponse.cs" />
</ItemGroup>
<ItemGroup>
<None Include="App.config" />

Binary file not shown.

View File

@@ -5,41 +5,50 @@ 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("</body>");
// 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()
{
@@ -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)

Binary file not shown.

View File

@@ -7,6 +7,9 @@
<add key="sms_smsusername" value="skessler1964@gmail.com"/>
<add key="sms_smspassword" value="xjfo isnf gmyi zovr"/>
<add key="sms_smsrecipients" value="skessler1964sms@gmail.com"/>
<add key="zoneedit_user" value="skessler1964"/>
<add key="zoneedit_password" value="4A536A7920309A11"/>
<add key="zoneedit_host" value="diversified-software.com"/>
</appSettings>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.6.2"/>

Binary file not shown.

View File

@@ -2,7 +2,7 @@
<configuration>
<appSettings>
<add key="poll_time_ms" value="300000"/>
<add key="notify_time_ms" value="4320000"/>
<add key="notify_time_ms" value="10800000"/>
<add key="sms_smtpaddress" value="smtp.gmail.com"/>
<add key="sms_smsusername" value="skessler1964@gmail.com"/>
<add key="sms_smspassword" value="xjfo isnf gmyi zovr"/>

Binary file not shown.

View File

@@ -7,6 +7,9 @@
<add key="sms_smsusername" value="skessler1964@gmail.com"/>
<add key="sms_smspassword" value="xjfo isnf gmyi zovr"/>
<add key="sms_smsrecipients" value="skessler1964sms@gmail.com"/>
<add key="zoneedit_user" value="skessler1964"/>
<add key="zoneedit_password" value="4A536A7920309A11"/>
<add key="zoneedit_host" value="diversified-software.com"/>
</appSettings>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.6.2"/>

Binary file not shown.

View File

@@ -2,6 +2,7 @@
<configuration>
<appSettings>
<add key="poll_time_ms" value="300000"/>
<add key="notify_time_ms" value="10800000"/>
<add key="sms_smtpaddress" value="smtp.gmail.com"/>
<add key="sms_smsusername" value="skessler1964@gmail.com"/>
<add key="sms_smspassword" value="xjfo isnf gmyi zovr"/>

View File

@@ -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)]<SUCCESS CODE="201" TEXT="no update required for diversified-software.com to 67.191.114.201" ZONE="diversified-software.com">
<SUCCESS CODE="200" TEXT="diversified-software.com updated to 67.191.114.201" ZONE="diversified-software.com">

View File

@@ -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

Binary file not shown.

Binary file not shown.