commit 7f4466d810ed3d898416cc396db4e275bf808c2f Author: Sean Kessler Date: Wed Mar 13 18:23:27 2024 -0400 Initial Commit diff --git a/App.config b/App.config new file mode 100644 index 0000000..ee8d2ae --- /dev/null +++ b/App.config @@ -0,0 +1,14 @@ + + + + + + + + + + + + + + diff --git a/IPMonitor.csproj b/IPMonitor.csproj new file mode 100644 index 0000000..79dc059 --- /dev/null +++ b/IPMonitor.csproj @@ -0,0 +1,65 @@ + + + + + Debug + AnyCPU + {45646B53-1805-4678-AC93-20F87BE46A95} + Exe + Properties + IPMonitor + IPMonitor + v4.6.2 + 512 + + + + AnyCPU + true + full + false + bin\Debug\ + DEBUG;TRACE + prompt + 4 + + + AnyCPU + pdbonly + true + bin\Release\ + TRACE + prompt + 4 + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/IPMonitor.sln b/IPMonitor.sln new file mode 100644 index 0000000..03082a7 --- /dev/null +++ b/IPMonitor.sln @@ -0,0 +1,22 @@ + +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio 2013 +VisualStudioVersion = 12.0.21005.1 +MinimumVisualStudioVersion = 10.0.40219.1 +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "IPMonitor", "IPMonitor.csproj", "{45646B53-1805-4678-AC93-20F87BE46A95}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Any CPU = Debug|Any CPU + Release|Any CPU = Release|Any CPU + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {45646B53-1805-4678-AC93-20F87BE46A95}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {45646B53-1805-4678-AC93-20F87BE46A95}.Debug|Any CPU.Build.0 = Debug|Any CPU + {45646B53-1805-4678-AC93-20F87BE46A95}.Release|Any CPU.ActiveCfg = Release|Any CPU + {45646B53-1805-4678-AC93-20F87BE46A95}.Release|Any CPU.Build.0 = Release|Any CPU + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection +EndGlobal diff --git a/IPMonitor.v12.suo b/IPMonitor.v12.suo new file mode 100644 index 0000000..b67d609 Binary files /dev/null and b/IPMonitor.v12.suo differ diff --git a/MDTrace.cs b/MDTrace.cs new file mode 100644 index 0000000..5fef20c --- /dev/null +++ b/MDTrace.cs @@ -0,0 +1,158 @@ +using System; +using System.Diagnostics; +using System.Threading; +using System.Text; +using System.Reflection; +using System.Runtime.Remoting.Messaging; + +// Filename: MarketDataTrace.cs +// Author:Sean Kessler +// Date:11/2005 + +namespace IPMonitor +{ + public enum LogLevel : uint + { + NONE=0x0000, + INFO=0x0002, + DEBUG=0x0004, + VERBOSE=0x0008 + }; +/// MarketDataTrace - Utility for . + public class MDTrace + { + private static LogLevel logLevel=LogLevel.DEBUG; + +/// MarketDataTrace - Private constructor prevents instantiation. +/// none + private MDTrace() + { + } + +/// LogLevel - Get/Set Log level. +/// The log level. +/// LogLevel + public static LogLevel LogLevel + { + get{return logLevel;} + set{logLevel=value;} + } +/// WriteLine - Writes a line of text to trace log. +/// string content of message to write. +/// void +// [Conditional("TRACE")] + public static void Write(LogLevel logLevel,string message) + { + if(MDTrace.logLevelWriteLine - Writes a line of text to trace log. +/// string content of message to write. +/// void +// [Conditional("TRACE")] + public static void WriteLine(string message) + { + WriteLine(LogLevel.DEBUG,GetCallerIP()+GetThreadRep()+GetLogLevelRep()+"["+DateTime.Now.ToString()+"]"+" "+GetMethodInfo()+message); + Console.WriteLine(message); + } +/// WriteLine - Writes a line of text to trace log. +/// string content of message to write. +/// void +// [Conditional("TRACE")] + public static void WriteLine(LogLevel logLevel,Exception exception) + { + if(MDTrace.logLevelWriteLine - Writes a line of text to trace log. +/// string content of message to write. +/// void +// [Conditional("TRACE")] + public static void WriteLine(LogLevel logLevel,string message) + { + if(MDTrace.logLevelIndent - set trace log indentation. +/// void +// [Conditional("TRACE")] + public static void Indent() + { + Trace.Indent(); + } +/// Unindent - set trace log indentation back. +/// void +// [Conditional("TRACE")] + public static void Unindent() + { + Trace.Unindent(); + } +/// Flush - Flush trace log buffers to disk. +/// void +// [Conditional("TRACE")] + public static void Flush() + { + Trace.Flush(); + } +/// GetLogLevel - Return current log level. +/// LogLevel + public static LogLevel GetLogLevel(String strLogLevel) + { + if(strLogLevel.Equals("debug"))return LogLevel.DEBUG; + else if(strLogLevel.Equals("verbose"))return LogLevel.VERBOSE; + else if(strLogLevel.Equals("info"))return LogLevel.INFO; + else return LogLevel.NONE; + } + +/// GetLogLevel - Return current log level. +/// LogLevel + private static string GetLogLevelRep() + { + if (MDTrace.logLevel == LogLevel.DEBUG) return "[TRACE.DEBUG]"; + else if (MDTrace.logLevel == LogLevel.VERBOSE) return "[TRACE.VERBOSE]"; + else if (MDTrace.logLevel == LogLevel.INFO) return "[TRACE.INFO]"; + else return "[TRACE.NONE]"; + } +/// GetThreadRep - Return threading information. +/// LogLevel + private static string GetThreadRep() + { + return "[Thread="+Thread.CurrentThread.GetHashCode()+"]"; + } +/// GetMethodInfo - Returns information about the calling method 2 frames up. +/// String + private static String GetMethodInfo() + { + StringBuilder sb=new StringBuilder(); + StackFrame frame=new StackFrame(2,true); + MethodBase methodBase=frame.GetMethod(); + ParameterInfo[] parameters=methodBase.GetParameters(); + sb.Append("[").Append(methodBase.DeclaringType.FullName).Append("::").Append(methodBase.Name).Append("("); + for(int index=0;indexGetCallerIP - Returns the calling methods IP address. +/// String + private static String GetCallerIP() + { + String hostName=(String)CallContext.GetData("HostName"); + String hostAddress=(String)CallContext.GetData("HostAddress"); + if(null!=hostName)hostName=hostName.Split('.')[0]; + if(null==hostName && null==hostAddress)return "[LOCAL]"; + return "["+hostAddress+"->"+hostName+"]"; + } + } +} diff --git a/Network.cs b/Network.cs new file mode 100644 index 0000000..81925c9 --- /dev/null +++ b/Network.cs @@ -0,0 +1,94 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Net.NetworkInformation; +using System.Text; +using System.Threading.Tasks; + +namespace IPMonitor +{ + public class NetworkStatus + { + private NetworkStatus() + { + } + /// + /// Indicates whether any network connection is available + /// Filter connections below a specified speed, as well as virtual network cards. + /// + /// + /// true if a network connection is available; otherwise, false. + /// + public static bool IsNetworkAvailable() + { + return IsNetworkAvailable(0); + } + public static bool IsInternetConnected() + { + try + { + Ping myPing = new Ping(); + String host = "google.com"; + byte[] buffer = new byte[32]; + int timeout = 1000; + PingOptions pingOptions = new PingOptions(); + PingReply reply = myPing.Send(host, timeout, buffer, pingOptions); + if (reply.Status == IPStatus.Success) + { + return true; + } + else if (reply.Status == IPStatus.TimedOut) + { + return true; + } + else + { + return false; + } + } + catch (Exception) + { + return false; + } + } + /// + /// Indicates whether any network connection is available. + /// Filter connections below a specified speed, as well as virtual network cards. + /// + /// The minimum speed required. Passing 0 will not filter connection using speed. + /// + /// true if a network connection is available; otherwise, false. + /// + public static bool IsNetworkAvailable(long minimumSpeed) + { + if (!NetworkInterface.GetIsNetworkAvailable()) + return false; + + foreach (NetworkInterface ni in NetworkInterface.GetAllNetworkInterfaces()) + { + // discard because of standard reasons + if ((ni.OperationalStatus != OperationalStatus.Up) || + (ni.NetworkInterfaceType == NetworkInterfaceType.Loopback) || + (ni.NetworkInterfaceType == NetworkInterfaceType.Tunnel)) + continue; + + // this allow to filter modems, serial, etc. + // I use 10000000 as a minimum speed for most cases + if (ni.Speed < minimumSpeed) + continue; + + // discard virtual cards (virtual box, virtual pc, etc.) + if ((ni.Description.IndexOf("virtual", StringComparison.OrdinalIgnoreCase) >= 0) || + (ni.Name.IndexOf("virtual", StringComparison.OrdinalIgnoreCase) >= 0)) + continue; + + // discard "Microsoft Loopback Adapter", it will not show as NetworkInterfaceType.Loopback but as Ethernet Card. + if (ni.Description.Equals("Microsoft Loopback Adapter", StringComparison.OrdinalIgnoreCase)) + continue; + + return true; + } + return false; + } + } +} diff --git a/Profiler.cs b/Profiler.cs new file mode 100644 index 0000000..6affa0f --- /dev/null +++ b/Profiler.cs @@ -0,0 +1,47 @@ +using System; +using System.Runtime.InteropServices; +using System.Collections; +using System.Text; + +// Filename: Profiler.cs +// Author:Sean Kessler + +namespace IPMonitor +{ + /// Profiler - Profiler utility class + public class Profiler + { + [DllImport("kernel32.dll")] + static extern uint GetTickCount(); + private uint elapsedTime; + private uint totalTime; + + public Profiler() + { + totalTime = GetTickCount(); + Start(); + } + public void Reset() + { + totalTime = GetTickCount(); + Start(); + } + public void Start() + { + elapsedTime = GetTickCount(); + } + public uint Split() + { + return GetTickCount() - elapsedTime; + } + public uint Stop() + { + return elapsedTime = GetTickCount() - elapsedTime; + } + public uint End() + { + return totalTime = GetTickCount() - totalTime; + } + } +} + diff --git a/Program.cs b/Program.cs new file mode 100644 index 0000000..91690ff --- /dev/null +++ b/Program.cs @@ -0,0 +1,127 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Configuration; +using System.Net; +using System.IO; +using System.Diagnostics; +using System.Threading; + +namespace IPMonitor +{ + class Program + { + public static String GetPublicIPAddress() + { + 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; + } + + public static void UpdateIPAddress(String ipAddress) + { + + + 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)); + } + } + } + + public static void WriteFile(String strPathFileName,String ipAddress) + { + if(File.Exists(strPathFileName))File.Delete(strPathFileName); + FileStream fileStream=new FileStream(strPathFileName,FileMode.Create,FileAccess.Write,FileShare.Read); + StreamWriter streamWriter=new StreamWriter(fileStream); + MDTrace.WriteLine(LogLevel.DEBUG,String.Format("Creating address file:{0}",strPathFileName)); + streamWriter.WriteLine(ipAddress); + streamWriter.Flush(); + streamWriter.Close(); + streamWriter.Dispose(); + } + + public static String ReadFile(String strPathFileName) + { + try + { + FileStream fileStream=new FileStream(strPathFileName,FileMode.Open,FileAccess.ReadWrite,FileShare.Read); + StreamReader streamReader=new StreamReader(fileStream); + String item=null; + item=streamReader.ReadLine(); + streamReader.Close(); + streamReader.Dispose(); + return item; + } + catch(Exception exception) + { + MDTrace.WriteLine(LogLevel.DEBUG,String.Format("[IPMonitor::ReadFile] Exception:{0}",exception.ToString())); + return null; + } + } + + public static void SendSMSEmail(string message) + { + String smsSMTPAddress = ConfigurationManager.AppSettings["sms_smtpaddress"]; + String smsUserName = ConfigurationManager.AppSettings["sms_smsusername"]; + String smsPassword = ConfigurationManager.AppSettings["sms_smspassword"]; + String[] smsRecipients = ConfigurationManager.AppSettings["sms_smsrecipients"].Split(','); + SMSClient.SendSMSEmail(message, smsUserName, smsRecipients, smsSMTPAddress, smsUserName, smsPassword); + } + + static void Main(string[] args) + { + int interval_ms = int.Parse(ConfigurationManager.AppSettings["poll_time_ms"]); + int notify_ms = int.Parse(ConfigurationManager.AppSettings["notify_time_ms"]); + + try + { + MDTrace.LogLevel = LogLevel.DEBUG; + String strLogFile = "ipmonitor.log"; + Utility.CopyFile(strLogFile,Utility.DateTimeToStringYYYYMMDDMMSSTT(DateTime.Now)+strLogFile); + Utility.DeleteFile(strLogFile); + Trace.Listeners.Add(new TextWriterTraceListener(strLogFile)); + + Profiler profiler=new Profiler(); + profiler.Start(); + while(true) + { + String ipAddress=GetPublicIPAddress(); + UpdateIPAddress(ipAddress); + try{Thread.Sleep(interval_ms);}catch{;} + if(profiler.Split()>=notify_ms) + { + SendSMSEmail(String.Format("IPMonitor IPAddress {0}",ipAddress)); + profiler.Start(); + } + } + } + catch(Exception exception) + { + MDTrace.WriteLine(LogLevel.DEBUG,String.Format("[IPMonitor] Exception:{0}",exception.ToString())); + } + } + } +} diff --git a/Properties/AssemblyInfo.cs b/Properties/AssemblyInfo.cs new file mode 100644 index 0000000..67582d7 --- /dev/null +++ b/Properties/AssemblyInfo.cs @@ -0,0 +1,36 @@ +using System.Reflection; +using System.Runtime.CompilerServices; +using System.Runtime.InteropServices; + +// General Information about an assembly is controlled through the following +// set of attributes. Change these attribute values to modify the information +// associated with an assembly. +[assembly: AssemblyTitle("IPMonitor")] +[assembly: AssemblyDescription("")] +[assembly: AssemblyConfiguration("")] +[assembly: AssemblyCompany("")] +[assembly: AssemblyProduct("IPMonitor")] +[assembly: AssemblyCopyright("Copyright © 2024")] +[assembly: AssemblyTrademark("")] +[assembly: AssemblyCulture("")] + +// Setting ComVisible to false makes the types in this assembly not visible +// to COM components. If you need to access a type in this assembly from +// COM, set the ComVisible attribute to true on that type. +[assembly: ComVisible(false)] + +// The following GUID is for the ID of the typelib if this project is exposed to COM +[assembly: Guid("7c9aa068-2aeb-4b6e-81e1-e5e34fd0e8a8")] + +// Version information for an assembly consists of the following four values: +// +// Major Version +// Minor Version +// Build Number +// Revision +// +// You can specify all the values or you can default the Build and Revision Numbers +// by using the '*' as shown below: +// [assembly: AssemblyVersion("1.0.*")] +[assembly: AssemblyVersion("1.0.0.0")] +[assembly: AssemblyFileVersion("1.0.0.0")] diff --git a/SMSClient.cs b/SMSClient.cs new file mode 100644 index 0000000..3743876 --- /dev/null +++ b/SMSClient.cs @@ -0,0 +1,93 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Net.Mail; +using System.Text; +using System.Threading.Tasks; + +namespace IPMonitor +{ + public class SMSClient + { + private SMSClient() + { + } + +// +// +// +// + public static void SendSMSEmail(string message, String from, String[] recipients,String smtpAddress,String userName,String password,int port=587) + { + String subject = string.Format("{0} {1}", message, DateTime.Now); + + try + { + if (!NetworkStatus.IsInternetConnected()) + { + MDTrace.WriteLine(LogLevel.DEBUG,"The internet is not connected. Cannot send SMSEmail."); + return; + } + MailMessage mailMessage = new MailMessage(); + mailMessage.From = new MailAddress(from); + mailMessage.Body = message; + mailMessage.Subject = subject; + mailMessage.IsBodyHtml = false; + foreach (String recipient in recipients) + { + mailMessage.To.Add(new MailAddress(recipient)); + } + SmtpClient smtpClient = new SmtpClient(smtpAddress,port); // smtp.gmail.com + smtpClient.UseDefaultCredentials = false; + smtpClient.Credentials = new System.Net.NetworkCredential(userName,password); // skessler1964@gmail.com MN5191306B + smtpClient.DeliveryMethod = SmtpDeliveryMethod.Network; + smtpClient.EnableSsl = true; + + smtpClient.Send(mailMessage); + smtpClient.Dispose(); + } + catch (System.Exception exception) + { + MDTrace.WriteLine(LogLevel.DEBUG,exception.ToString()); + } + } + + public static void SendEmail(string message, String from, String[] recipients,String smtpAddress,String userName,String password,int port=587) + { + String subject = string.Format("{0} {1}", message, DateTime.Now); + + try + { + if (!NetworkStatus.IsInternetConnected()) + { + MDTrace.WriteLine(LogLevel.DEBUG,"The internet is not connected. Cannot send Email."); + return; + } + MailMessage mailMessage = new MailMessage(); + mailMessage.From = new MailAddress(from); + mailMessage.Body = message; + mailMessage.Subject = subject; + mailMessage.IsBodyHtml = false; + foreach (String recipient in recipients) + { + mailMessage.To.Add(new MailAddress(recipient)); + } + SmtpClient smtpClient = new SmtpClient(smtpAddress,port); // smtp.gmail.com + smtpClient.UseDefaultCredentials = false; + smtpClient.Credentials = new System.Net.NetworkCredential(userName,password); // skessler1964@gmail.com MN5191306B + smtpClient.DeliveryMethod = SmtpDeliveryMethod.Network; + smtpClient.EnableSsl = true; + + smtpClient.Send(mailMessage); + smtpClient.Dispose(); + } + catch (System.Exception exception) + { + MDTrace.WriteLine(LogLevel.DEBUG,exception.ToString()); + } + } + + + + } +} diff --git a/Utility.cs b/Utility.cs new file mode 100644 index 0000000..3521ef2 --- /dev/null +++ b/Utility.cs @@ -0,0 +1,627 @@ +using System; +using System.Text; +using System.IO.Compression; +using System.IO; +using System.Globalization; +using System.Linq; +using System.Collections.Generic; +using Microsoft.Win32; +using System.Diagnostics; +using System.Security.Principal; +using System.Threading; +using ThreadState=System.Threading.ThreadState; + +namespace IPMonitor +{ + public class Utility + { + private static DateTime epoch = DateTime.Parse("01-01-0001"); + private static TimeSpan oneDay=new TimeSpan(1,0,0,0); + + + public static String ThreadStateToString(Thread thread) + { + switch(thread.ThreadState) + { + case ThreadState.Running : + return "Running"; + case ThreadState.StopRequested : + return "StopRequested"; + case ThreadState.SuspendRequested : + return "SuspendRequested"; + case ThreadState.Background : + return "Background"; + case ThreadState.Unstarted : + return "Unstarted"; + case ThreadState.Stopped : + return "Stopped"; + case ThreadState.WaitSleepJoin : + return "WaitSleepJoin"; + case ThreadState.Suspended : + return "Suspended"; + case ThreadState.AbortRequested : + return "AbortRequested"; + case ThreadState.Aborted : + return "Aborted"; + default : + return "Unknown"; + } + } + public static long DateToUnixDate(DateTime dateTime) + { + DateTime javascriptEpoch=DateTime.Parse("01-01-1970 00:00:00"); + DateTime eod=new DateTime(dateTime.Year,dateTime.Month,dateTime.Day,23,0,0); // request end of day + TimeSpan ts=eod-javascriptEpoch; + long longDate=(long)ts.TotalSeconds; + return longDate; + } + public static DateTime UnixDateToDate(long yahooDate) + { + DateTime javascriptEpoch=DateTime.Parse("01-01-1970 00:00:00"); + TimeSpan timespan=TimeSpan.FromSeconds((double)yahooDate); + DateTime date=javascriptEpoch+timespan; + return date; + } + public static void RemoveLogFiles(String strFolder=null) + { + if(null==strFolder)strFolder=Directory.GetCurrentDirectory(); + String[] logFiles=Directory.GetFiles(strFolder); + if(null==logFiles || 0==logFiles.Length)return; + logFiles=logFiles.Where(x => x.EndsWith(".log",StringComparison.InvariantCultureIgnoreCase)).ToArray(); + if(null==logFiles || 0==logFiles.Length)return; + foreach(String logFile in logFiles) + { + try + { + MDTrace.WriteLine(LogLevel.DEBUG,String.Format("Removing {0}",logFile)); + File.Delete(logFile); + } + catch(Exception){;} + } + } + public static String Pad(string str, char filler, int length) + { + int stringLength = str.Length; + if (stringLength >= length) return str; + StringBuilder sb = new StringBuilder(); + + while (stringLength < length) + { + sb.Append(filler); + stringLength++; + } + return sb.ToString() + str; + } + public static bool Is64Bit() + { + if(IntPtr.Size.Equals(8))return true; + return false; + } + public static bool IsAdministrator() + { + return (new WindowsPrincipal(WindowsIdentity.GetCurrent())).IsInRole(WindowsBuiltInRole.Administrator); + } + public static String RemoveHtml(String strItem) + { + if(null==strItem)return null; + String[] codes = { "'","»" }; + if(null==strItem)return strItem; + foreach (String code in codes) + { + strItem = strItem.Replace(code,"'"); + } + strItem=strItem.Replace("&","&"); + strItem=strItem.Replace("‘","'"); + strItem=strItem.Replace("’","'"); + strItem=strItem.Replace("—","-"); + strItem=strItem.Replace("“",@""""); + strItem=strItem.Replace("“",@""""); + strItem=strItem.Replace("”",@""""); + strItem=strItem.Replace("”",@""""); + strItem=strItem.Replace("–","-"); + return strItem; + } + public static String RemoveDivs(String strItem) + { + StringBuilder sb=new StringBuilder(); + bool inDiv=false; + if(null==strItem)return strItem; + for(int index=0;index'))inDiv=false; + else if(!inDiv)sb.Append(ch); + } + return sb.ToString(); + } + public static int CharToNum(char ch) + { + return (int)ch-48; + } + public static String RemoveCC(String item) + { + StringBuilder sb=new StringBuilder(); + foreach(char ch in item) + { + if(!Char.IsControl(ch)) sb.Append(ch); + } + return sb.ToString(); + } + public static Stream StreamFromString(string s) + { + var stream=new MemoryStream(); + var writer=new StreamWriter(stream); + writer.Write(s); + writer.Flush(); + stream.Position=0; + return stream; + } + public static String RemoveQuotes(String strItem) + { + if (String.IsNullOrEmpty(strItem)) return null; + if(strItem.StartsWith("\""))strItem=strItem.Substring(1); + if(strItem.EndsWith("\""))strItem=strItem.Substring(0,strItem.Length-1); + return strItem; + } + public static String BetweenString(String strItem, String strBegin, String strEnd) + { + if (null == strItem) return null; + int index=-1; + if(null==strBegin)index=0; + else index = strItem.IndexOf(strBegin); + if (-1 == index) return null; + String str = null; + if(null!=strBegin)str=strItem.Substring(index + strBegin.Length); + else str=strItem; + if(null==strEnd)return str; + index = str.IndexOf(strEnd); + if (-1 == index) return null; + StringBuilder sb = new StringBuilder(); + for (int strIndex = 0; strIndex < str.Length; strIndex++) + { + if (index == strIndex) break; + sb.Append(str[strIndex]); + } + return sb.ToString(); + } + public static String RemoveAfter(String strItem, char charItem) + { + StringBuilder sb = new StringBuilder(); + for (int index = 0; index < strItem.Length; index++) + { + char ch = strItem[index]; + if (ch.Equals(charItem)) break; + sb.Append(ch); + } + return sb.ToString(); + } + public static bool OutOfRange(double value) + { + return value > 100000000000000000000.00 || value< -99999999999999999999.99; + } + public static String RemoveControlChars(String strItem) + { + StringBuilder sb=new StringBuilder(); + for(int index=0;index=1000.00) formatString.Append("{0:0,0."); + else formatString.Append("{0:0."); + for(int index=0;index list,char separator=',') + { + StringBuilder sb=new StringBuilder(); + if (null == list || 0 == list.Count) return null; + for(int index=0;index ToList(String items,char separator=',') + { + List list = items.Split(separator).ToList(); + list=(from String str in list where !String.IsNullOrEmpty(str) select str.Trim()).ToList(); + return list; + } + public static String FromList(List items,String postFix=",") + { + StringBuilder sb=new StringBuilder(); + for(int index=0;index 0) outputStream.Write(decompressedBytesBuffer, 0, count); + else break; + } + decompressionStream.Close(); + compressedStream.Close(); + String strDecompressed = System.Text.Encoding.UTF8.GetString(outputStream.ToArray()); + outputStream.Close(); + outputStream = null; + compressedStream = null; + decompressionStream = null; + return strDecompressed; + } + catch (Exception exception) + { + MDTrace.WriteLine(LogLevel.DEBUG,exception); + return null; + } + finally + { + if (null != outputStream) + { + outputStream.Close(); + outputStream = null; + } + if (null != decompressionStream) + { + decompressionStream.Close(); + decompressionStream = null; + } + if (null != compressedStream) + { + compressedStream.Close(); + compressedStream = null; + } + } + } + public static void LaunchBrowserSearch(String searchTerm) + { + Process.Start("https://www.google.com/search?q="+Uri.EscapeDataString(searchTerm)+"/"); + } + public static bool IsZeroOrNaN(double value) + { + return IsNaN(value)||IsZero(value); + } + private static bool IsZero(double value) + { + if(value==0.00)return true; + return false; + } + private static bool IsNaN(double value) + { + return double.IsNaN(value); + } + public static bool DeleteFile(String pathFileName) + { + if(!File.Exists(pathFileName))return false; + try{File.Delete(pathFileName);}catch(Exception){return false;} + return true; + } + + public static bool CopyFile(String pathSrcFileName,String pathDstFileName) + { + if(!File.Exists(pathSrcFileName))return false; + try{File.Copy(pathSrcFileName,pathDstFileName);}catch(Exception){return false;} + return true; + } + } +} \ No newline at end of file diff --git a/bin/Debug/IPMonitor.exe b/bin/Debug/IPMonitor.exe new file mode 100644 index 0000000..1dc6c13 Binary files /dev/null and b/bin/Debug/IPMonitor.exe differ diff --git a/bin/Debug/IPMonitor.exe.config b/bin/Debug/IPMonitor.exe.config new file mode 100644 index 0000000..ee8d2ae --- /dev/null +++ b/bin/Debug/IPMonitor.exe.config @@ -0,0 +1,14 @@ + + + + + + + + + + + + + + diff --git a/bin/Debug/IPMonitor.pdb b/bin/Debug/IPMonitor.pdb new file mode 100644 index 0000000..70502bf Binary files /dev/null and b/bin/Debug/IPMonitor.pdb differ diff --git a/bin/Debug/IPMonitor.vshost.exe b/bin/Debug/IPMonitor.vshost.exe new file mode 100644 index 0000000..c0dfecc Binary files /dev/null and b/bin/Debug/IPMonitor.vshost.exe differ diff --git a/bin/Debug/IPMonitor.vshost.exe.config b/bin/Debug/IPMonitor.vshost.exe.config new file mode 100644 index 0000000..ee8d2ae --- /dev/null +++ b/bin/Debug/IPMonitor.vshost.exe.config @@ -0,0 +1,14 @@ + + + + + + + + + + + + + + diff --git a/bin/Debug/IPMonitor.vshost.exe.manifest b/bin/Debug/IPMonitor.vshost.exe.manifest new file mode 100644 index 0000000..061c9ca --- /dev/null +++ b/bin/Debug/IPMonitor.vshost.exe.manifest @@ -0,0 +1,11 @@ + + + + + + + + + + + diff --git a/bin/Debug/ipaddress.txt b/bin/Debug/ipaddress.txt new file mode 100644 index 0000000..0a3593b --- /dev/null +++ b/bin/Debug/ipaddress.txt @@ -0,0 +1 @@ +67.191.114.201 diff --git a/bin/Debug/ipmonitor.log b/bin/Debug/ipmonitor.log new file mode 100644 index 0000000..922fcd2 --- /dev/null +++ b/bin/Debug/ipmonitor.log @@ -0,0 +1 @@ +[LOCAL][Thread=9][TRACE.DEBUG][3/13/2024 04:32:56 PM] [IPMonitor.Program::WriteFile(strPathFileName,ipAddress)]Creating address file:ipaddress.txt diff --git a/bin/Release/20240313061456PMipmonitor.log b/bin/Release/20240313061456PMipmonitor.log new file mode 100644 index 0000000..40200af --- /dev/null +++ b/bin/Release/20240313061456PMipmonitor.log @@ -0,0 +1 @@ +[LOCAL][Thread=1][TRACE.DEBUG][3/13/2024 6:10:56 PM] [IPMonitor.Program::WriteFile(strPathFileName,ipAddress)]Creating address file:ipaddress.txt diff --git a/bin/Release/IPMonitor.exe b/bin/Release/IPMonitor.exe new file mode 100644 index 0000000..1dc6c13 Binary files /dev/null and b/bin/Release/IPMonitor.exe differ diff --git a/bin/Release/IPMonitor.exe.config b/bin/Release/IPMonitor.exe.config new file mode 100644 index 0000000..ee8d2ae --- /dev/null +++ b/bin/Release/IPMonitor.exe.config @@ -0,0 +1,14 @@ + + + + + + + + + + + + + + diff --git a/bin/Release/IPMonitor.pdb b/bin/Release/IPMonitor.pdb new file mode 100644 index 0000000..70502bf Binary files /dev/null and b/bin/Release/IPMonitor.pdb differ diff --git a/bin/Release/IPMonitor.vshost.exe b/bin/Release/IPMonitor.vshost.exe new file mode 100644 index 0000000..c0dfecc Binary files /dev/null and b/bin/Release/IPMonitor.vshost.exe differ diff --git a/bin/Release/IPMonitor.vshost.exe.config b/bin/Release/IPMonitor.vshost.exe.config new file mode 100644 index 0000000..06058de --- /dev/null +++ b/bin/Release/IPMonitor.vshost.exe.config @@ -0,0 +1,13 @@ + + + + + + + + + + + + + diff --git a/bin/Release/IPMonitor.vshost.exe.manifest b/bin/Release/IPMonitor.vshost.exe.manifest new file mode 100644 index 0000000..061c9ca --- /dev/null +++ b/bin/Release/IPMonitor.vshost.exe.manifest @@ -0,0 +1,11 @@ + + + + + + + + + + + diff --git a/bin/Release/ipaddress.txt b/bin/Release/ipaddress.txt new file mode 100644 index 0000000..0a3593b --- /dev/null +++ b/bin/Release/ipaddress.txt @@ -0,0 +1 @@ +67.191.114.201 diff --git a/bin/Release/ipmonitor.log b/bin/Release/ipmonitor.log new file mode 100644 index 0000000..680bcce --- /dev/null +++ b/bin/Release/ipmonitor.log @@ -0,0 +1 @@ +[LOCAL][Thread=1][TRACE.DEBUG][3/13/2024 6:14:56 PM] [IPMonitor.Program::WriteFile(strPathFileName,ipAddress)]Creating address file:ipaddress.txt diff --git a/obj/Debug/DesignTimeResolveAssemblyReferencesInput.cache b/obj/Debug/DesignTimeResolveAssemblyReferencesInput.cache new file mode 100644 index 0000000..1dfb5e8 Binary files /dev/null and b/obj/Debug/DesignTimeResolveAssemblyReferencesInput.cache differ diff --git a/obj/Debug/IPMonitor.csproj.FileListAbsolute.txt b/obj/Debug/IPMonitor.csproj.FileListAbsolute.txt new file mode 100644 index 0000000..88e7acc --- /dev/null +++ b/obj/Debug/IPMonitor.csproj.FileListAbsolute.txt @@ -0,0 +1,9 @@ +C:\Visual Studio\IPMonitor\bin\Debug\IPMonitor.exe.config +C:\Visual Studio\IPMonitor\bin\Debug\IPMonitor.exe +C:\Visual Studio\IPMonitor\bin\Debug\IPMonitor.pdb +C:\Visual Studio\IPMonitor\obj\Debug\IPMonitor.csprojResolveAssemblyReference.cache +C:\Visual Studio\IPMonitor\obj\Debug\IPMonitor.exe +C:\Visual Studio\IPMonitor\obj\Debug\IPMonitor.pdb +C:\boneyard\IPMonitor\bin\Debug\IPMonitor.exe.config +C:\boneyard\IPMonitor\obj\Debug\IPMonitor.exe +C:\boneyard\IPMonitor\obj\Debug\IPMonitor.pdb diff --git a/obj/Debug/IPMonitor.csprojResolveAssemblyReference.cache b/obj/Debug/IPMonitor.csprojResolveAssemblyReference.cache new file mode 100644 index 0000000..d7696cb Binary files /dev/null and b/obj/Debug/IPMonitor.csprojResolveAssemblyReference.cache differ diff --git a/obj/Debug/IPMonitor.exe b/obj/Debug/IPMonitor.exe new file mode 100644 index 0000000..1dc6c13 Binary files /dev/null and b/obj/Debug/IPMonitor.exe differ diff --git a/obj/Debug/IPMonitor.pdb b/obj/Debug/IPMonitor.pdb new file mode 100644 index 0000000..70502bf Binary files /dev/null and b/obj/Debug/IPMonitor.pdb differ diff --git a/obj/Debug/TemporaryGeneratedFile_036C0B5B-1481-4323-8D20-8F5ADCB23D92.cs b/obj/Debug/TemporaryGeneratedFile_036C0B5B-1481-4323-8D20-8F5ADCB23D92.cs new file mode 100644 index 0000000..e69de29 diff --git a/obj/Debug/TemporaryGeneratedFile_5937a670-0e60-4077-877b-f7221da3dda1.cs b/obj/Debug/TemporaryGeneratedFile_5937a670-0e60-4077-877b-f7221da3dda1.cs new file mode 100644 index 0000000..e69de29 diff --git a/obj/Debug/TemporaryGeneratedFile_E7A71F73-0F8D-4B9B-B56E-8E70B10BC5D3.cs b/obj/Debug/TemporaryGeneratedFile_E7A71F73-0F8D-4B9B-B56E-8E70B10BC5D3.cs new file mode 100644 index 0000000..e69de29