Skip to content

Commit fc9f1d4

Browse files
author
chrisdee
committed
Added IPWatchdog monitoring solution
1 parent e62f692 commit fc9f1d4

29 files changed

+1007
-0
lines changed

Network/IpWatchdog/.gitignore

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
#OS junk files
2+
[Tt]humbs.db
3+
*.DS_Store
4+
5+
#Visual Studio files
6+
*.[Oo]bj
7+
*.user
8+
*.aps
9+
*.pch
10+
*.vspscc
11+
*.vssscc
12+
*_i.c
13+
*_p.c
14+
*.ncb
15+
*.suo
16+
*.tlb
17+
*.tlh
18+
*.bak
19+
*.[Cc]ache
20+
*.ilk
21+
*.log
22+
*.lib
23+
*.sbr
24+
*.sdf
25+
*.opensdf
26+
*.unsuccessfulbuild
27+
ipch/
28+
obj/
29+
[Bb]in
30+
[Dd]ebug*/
31+
[Rr]elease*/
32+
33+
#Tooling
34+
_ReSharper*/
35+
*.resharper
36+
[Tt]est[Rr]esult*
37+
38+
#Project files
39+
[Bb]uild/
40+
41+
#Subversion files
42+
.svn
43+
44+
# Office Temp Files
45+
~$*
46+
47+
#NuGet
48+
packages/
49+
50+
# visual studio database projects
51+
*.dbmdl

Network/IpWatchdog/IpWatchDog.sln

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
2+
Microsoft Visual Studio Solution File, Format Version 11.00
3+
# Visual Studio 2010
4+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "IpWatchDog", "IpWatchDog\IpWatchDog.csproj", "{0A20C9D6-E6BB-40F4-A166-56B8612FECAA}"
5+
EndProject
6+
Global
7+
GlobalSection(SolutionConfigurationPlatforms) = preSolution
8+
Debug|x86 = Debug|x86
9+
Release|x86 = Release|x86
10+
EndGlobalSection
11+
GlobalSection(ProjectConfigurationPlatforms) = postSolution
12+
{0A20C9D6-E6BB-40F4-A166-56B8612FECAA}.Debug|x86.ActiveCfg = Debug|x86
13+
{0A20C9D6-E6BB-40F4-A166-56B8612FECAA}.Debug|x86.Build.0 = Debug|x86
14+
{0A20C9D6-E6BB-40F4-A166-56B8612FECAA}.Release|x86.ActiveCfg = Release|x86
15+
{0A20C9D6-E6BB-40F4-A166-56B8612FECAA}.Release|x86.Build.0 = Release|x86
16+
EndGlobalSection
17+
GlobalSection(SolutionProperties) = preSolution
18+
HideSolutionNode = FALSE
19+
EndGlobalSection
20+
EndGlobal

Network/IpWatchdog/IpWatchDog.txt

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
URLs: http://www.codeproject.com/Articles/419660/IP-Watchdog-Simple-Windows-Service-Written-in-Csha
2+
3+
GitHub: https://github.com/ikriv/IpWatchDog
4+
5+
Usage:
6+
7+
Go to either 'Debug' or 'Release' in the bin directory
8+
9+
\IpWatchdog\IpWatchDog\bin
10+
11+
With PowerShell start the 'IpWatchDog.exe' with the -h switch
12+
13+
.\IpWatchDog.exe -h
14+
15+
Command line arguments:
16+
-i or -install : install the service (must be an administrator)
17+
-u or -uninstall: uninstall the service (must be an administrator)
18+
-s or -start: start the service (must be an administrator)
19+
-p or -stop: stop running service (must be an administrator)
20+
-c or -console: run in console mode
21+
22+
Example to run this in console mode:
23+
24+
.\IpWatchDog.exe -c
25+
26+
You can change your SMTP configuration settings in the 'IpWatchDog.exe' configuration file:
27+
28+
IpWatchDog.exe
29+
30+
31+
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
<?xml version="1.0"?>
2+
<configuration>
3+
<appSettings>
4+
<add key="PollingTimeoutSeconds" value="900"/>
5+
<add key="MailFrom" value="[email protected]"/>
6+
<add key="MailTo" value="[email protected]"/>
7+
<add key="Subject" value="IP changed"/>
8+
<add key="SmtpHost" value="mail.example.com"/>
9+
</appSettings>
10+
<startup><supportedRuntime version="v2.0.50727"/></startup></configuration>
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
using System;
2+
using System.Configuration;
3+
4+
namespace IpWatchDog
5+
{
6+
class AppConfig
7+
{
8+
public int PollingTimeoutSeconds
9+
{
10+
get { return Int32.Parse(Config("PollingTimeoutSeconds")); }
11+
}
12+
13+
public string MailFrom
14+
{
15+
get { return Config("MailFrom"); }
16+
}
17+
18+
public string MailTo
19+
{
20+
get { return Config("MailTo"); }
21+
}
22+
23+
public string SmtpHost
24+
{
25+
get { return Config("SmtpHost"); }
26+
}
27+
28+
public string Subject
29+
{
30+
get { return Config("Subject"); }
31+
}
32+
33+
private string Config(string arg)
34+
{
35+
return ConfigurationManager.AppSettings[arg];
36+
}
37+
}
38+
}
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
using IpWatchDog.Install;
2+
using IpWatchDog.Log;
3+
using IpWatchDog.Runners;
4+
5+
namespace IpWatchDog
6+
{
7+
class Configurator
8+
{
9+
private ILog _log;
10+
private bool _isConsole;
11+
12+
public Configurator(bool isConsole)
13+
{
14+
_isConsole = isConsole;
15+
_log =
16+
isConsole ?
17+
(ILog)new ConsoleLog() :
18+
new SystemLog(StringConstants.ServiceName);
19+
}
20+
21+
public IRunner CreateRunner()
22+
{
23+
var service = CreateWatchDogService();
24+
return _isConsole ?
25+
(IRunner)new ConsoleRunner(service) :
26+
new ServiceRunner(service, StringConstants.ServiceName);
27+
}
28+
29+
public InstallUtil CreateInstaller()
30+
{
31+
return new InstallUtil(_log);
32+
}
33+
34+
public IService CreateServiceController()
35+
{
36+
return new ServiceController(_log);
37+
}
38+
39+
private IService CreateWatchDogService()
40+
{
41+
var config = new AppConfig();
42+
43+
return new IpWatchDogService(
44+
_log,
45+
config,
46+
new IpPersistor(_log),
47+
new WebIpRetriever(_log),
48+
new MailIpNotifier(_log, config));
49+
}
50+
}
51+
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
namespace IpWatchDog
2+
{
3+
interface IIpNotifier
4+
{
5+
void OnIpChanged(string oldIp, string newIp);
6+
}
7+
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
namespace IpWatchDog
2+
{
3+
interface IIpPersistor : IIpRetriever
4+
{
5+
void SaveIp(string ip);
6+
}
7+
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
namespace IpWatchDog
2+
{
3+
interface IIpRetriever
4+
{
5+
string GetIp();
6+
}
7+
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
namespace IpWatchDog
2+
{
3+
interface IService
4+
{
5+
void Start();
6+
void Stop();
7+
}
8+
}

0 commit comments

Comments
 (0)