Lang nichts mehr passiert, refactoring ist geil
@ -1,6 +1,6 @@
|
||||
|
||||
Microsoft Visual Studio Solution File, Format Version 11.00
|
||||
# Visual Studio 2010
|
||||
Microsoft Visual Studio Solution File, Format Version 12.00
|
||||
# Visual Studio 2012
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "NetMonitorClient", "NetMonitorClient\NetMonitorClient.csproj", "{718693A0-06A3-4765-801D-33842861AA61}"
|
||||
EndProject
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "NetMonitorServer", "NetMonitorServer\NetMonitorServer.csproj", "{7813196F-D729-44A2-81C7-82BB83E207F5}"
|
||||
@ -9,6 +9,12 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "NetMonitorConsole", "NetMon
|
||||
EndProject
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "NetOpenVPNGUI", "NetOpenVPNGUI\NetOpenVPNGUI.csproj", "{23485575-888C-4990-A4C8-6C74563F6A85}"
|
||||
EndProject
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Utils", "..\Utils\Utils\Utils.csproj", "{FAC8CE64-BF13-4ECE-8097-AEB5DD060098}"
|
||||
EndProject
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "NetMonitorUtils", "NetMonitorUtils\NetMonitorUtils.csproj", "{45EE003D-5572-48FE-B90E-6BFE18D9EEC8}"
|
||||
EndProject
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "NetMonitorTray", "NetMonitorTray\NetMonitorTray.csproj", "{0B85C838-3295-4FDA-9B07-4F5B3681BE2F}"
|
||||
EndProject
|
||||
Global
|
||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||
Debug|Any CPU = Debug|Any CPU
|
||||
@ -59,6 +65,36 @@ Global
|
||||
{23485575-888C-4990-A4C8-6C74563F6A85}.Release|Mixed Platforms.Build.0 = Release|x86
|
||||
{23485575-888C-4990-A4C8-6C74563F6A85}.Release|x86.ActiveCfg = Release|x86
|
||||
{23485575-888C-4990-A4C8-6C74563F6A85}.Release|x86.Build.0 = Release|x86
|
||||
{FAC8CE64-BF13-4ECE-8097-AEB5DD060098}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{FAC8CE64-BF13-4ECE-8097-AEB5DD060098}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{FAC8CE64-BF13-4ECE-8097-AEB5DD060098}.Debug|Mixed Platforms.ActiveCfg = Debug|Any CPU
|
||||
{FAC8CE64-BF13-4ECE-8097-AEB5DD060098}.Debug|Mixed Platforms.Build.0 = Debug|Any CPU
|
||||
{FAC8CE64-BF13-4ECE-8097-AEB5DD060098}.Debug|x86.ActiveCfg = Debug|Any CPU
|
||||
{FAC8CE64-BF13-4ECE-8097-AEB5DD060098}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{FAC8CE64-BF13-4ECE-8097-AEB5DD060098}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
{FAC8CE64-BF13-4ECE-8097-AEB5DD060098}.Release|Mixed Platforms.ActiveCfg = Release|Any CPU
|
||||
{FAC8CE64-BF13-4ECE-8097-AEB5DD060098}.Release|Mixed Platforms.Build.0 = Release|Any CPU
|
||||
{FAC8CE64-BF13-4ECE-8097-AEB5DD060098}.Release|x86.ActiveCfg = Release|Any CPU
|
||||
{45EE003D-5572-48FE-B90E-6BFE18D9EEC8}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{45EE003D-5572-48FE-B90E-6BFE18D9EEC8}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{45EE003D-5572-48FE-B90E-6BFE18D9EEC8}.Debug|Mixed Platforms.ActiveCfg = Debug|Any CPU
|
||||
{45EE003D-5572-48FE-B90E-6BFE18D9EEC8}.Debug|Mixed Platforms.Build.0 = Debug|Any CPU
|
||||
{45EE003D-5572-48FE-B90E-6BFE18D9EEC8}.Debug|x86.ActiveCfg = Debug|Any CPU
|
||||
{45EE003D-5572-48FE-B90E-6BFE18D9EEC8}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{45EE003D-5572-48FE-B90E-6BFE18D9EEC8}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
{45EE003D-5572-48FE-B90E-6BFE18D9EEC8}.Release|Mixed Platforms.ActiveCfg = Release|Any CPU
|
||||
{45EE003D-5572-48FE-B90E-6BFE18D9EEC8}.Release|Mixed Platforms.Build.0 = Release|Any CPU
|
||||
{45EE003D-5572-48FE-B90E-6BFE18D9EEC8}.Release|x86.ActiveCfg = Release|Any CPU
|
||||
{0B85C838-3295-4FDA-9B07-4F5B3681BE2F}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{0B85C838-3295-4FDA-9B07-4F5B3681BE2F}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{0B85C838-3295-4FDA-9B07-4F5B3681BE2F}.Debug|Mixed Platforms.ActiveCfg = Debug|Any CPU
|
||||
{0B85C838-3295-4FDA-9B07-4F5B3681BE2F}.Debug|Mixed Platforms.Build.0 = Debug|Any CPU
|
||||
{0B85C838-3295-4FDA-9B07-4F5B3681BE2F}.Debug|x86.ActiveCfg = Debug|Any CPU
|
||||
{0B85C838-3295-4FDA-9B07-4F5B3681BE2F}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{0B85C838-3295-4FDA-9B07-4F5B3681BE2F}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
{0B85C838-3295-4FDA-9B07-4F5B3681BE2F}.Release|Mixed Platforms.ActiveCfg = Release|Any CPU
|
||||
{0B85C838-3295-4FDA-9B07-4F5B3681BE2F}.Release|Mixed Platforms.Build.0 = Release|Any CPU
|
||||
{0B85C838-3295-4FDA-9B07-4F5B3681BE2F}.Release|x86.ActiveCfg = Release|Any CPU
|
||||
EndGlobalSection
|
||||
GlobalSection(SolutionProperties) = preSolution
|
||||
HideSolutionNode = FALSE
|
||||
|
@ -115,7 +115,6 @@
|
||||
<DependentUpon>Settings.settings</DependentUpon>
|
||||
<DesignTimeSharedInput>True</DesignTimeSharedInput>
|
||||
</Compile>
|
||||
<Compile Include="ServiceControl.cs" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<BootstrapperPackage Include="Microsoft.Net.Client.3.5">
|
||||
|
@ -1,141 +0,0 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.ServiceProcess;
|
||||
using System.Net.Sockets;
|
||||
using System.Net;
|
||||
|
||||
namespace NetMonitorClient
|
||||
{
|
||||
public class ServiceControl
|
||||
{
|
||||
private UdpClient net_send;
|
||||
private IPEndPoint net_send_port;
|
||||
private UdpClient net_gets;
|
||||
private IPEndPoint net_gets_port;
|
||||
public ServiceControl(string name)
|
||||
{
|
||||
ServiceController sc = new ServiceController();
|
||||
sc.ServiceName = name;
|
||||
//if (sc.Status != ServiceControllerStatus.Running)
|
||||
//{
|
||||
// sc.Start();
|
||||
//}
|
||||
this.net_send = new UdpClient();
|
||||
this.net_send_port = new IPEndPoint(IPAddress.Parse("127.0.0.1"), 34523);
|
||||
this.net_gets = new UdpClient(34524);
|
||||
this.net_gets_port = new IPEndPoint(IPAddress.Loopback, 0);
|
||||
}
|
||||
|
||||
internal bool setNetworkAuto(string adapter)
|
||||
{
|
||||
if (adapter == null)
|
||||
{
|
||||
System.Windows.Forms.MessageBox.Show("Adapter ist not Set!");
|
||||
return false;
|
||||
}
|
||||
byte[] data = Encoding.UTF8.GetBytes("NET AUTO "+adapter);
|
||||
this.net_send.Send(data, data.Length, this.net_send_port);
|
||||
return Boolean.Parse(Encoding.UTF8.GetString(net_gets.Receive(ref net_gets_port)));
|
||||
}
|
||||
|
||||
internal bool setNetworkIp(string ip, string subnet, string gateway, string adapter)
|
||||
{
|
||||
if (ip == null)
|
||||
{
|
||||
System.Windows.Forms.MessageBox.Show("IP address not Set!");
|
||||
return false;
|
||||
}
|
||||
if (subnet == null)
|
||||
{
|
||||
System.Windows.Forms.MessageBox.Show("Subnet address not Set!");
|
||||
return false;
|
||||
}
|
||||
if (gateway == null)
|
||||
{
|
||||
System.Windows.Forms.MessageBox.Show("Gateway address not Set!");
|
||||
return false;
|
||||
}
|
||||
if (adapter == null)
|
||||
{
|
||||
System.Windows.Forms.MessageBox.Show("Adapter ist not Set!");
|
||||
return false;
|
||||
}
|
||||
byte[] data = Encoding.UTF8.GetBytes("NET IP " + ip + " " + subnet + " " + gateway + " " + adapter);
|
||||
this.net_send.Send(data, data.Length, this.net_send_port);
|
||||
return Boolean.Parse(Encoding.UTF8.GetString(net_gets.Receive(ref net_gets_port)));
|
||||
}
|
||||
|
||||
internal bool setNetworkDNS(string dns, string adapter)
|
||||
{
|
||||
if (dns == null)
|
||||
{
|
||||
System.Windows.Forms.MessageBox.Show("DNS address not Set!");
|
||||
return false;
|
||||
}
|
||||
if (adapter == null)
|
||||
{
|
||||
System.Windows.Forms.MessageBox.Show("Adapter ist not Set!");
|
||||
return false;
|
||||
}
|
||||
byte[] data = Encoding.UTF8.GetBytes("NET DNS " + dns + " " + adapter);
|
||||
this.net_send.Send(data, data.Length, this.net_send_port);
|
||||
return Boolean.Parse(Encoding.UTF8.GetString(net_gets.Receive(ref net_gets_port)));
|
||||
}
|
||||
|
||||
internal bool setNetworkWINS(string wins, string adapter)
|
||||
{
|
||||
if (wins == null)
|
||||
{
|
||||
System.Windows.Forms.MessageBox.Show("WINS address not Set!");
|
||||
return false;
|
||||
}
|
||||
if (adapter == null)
|
||||
{
|
||||
System.Windows.Forms.MessageBox.Show("Adapter ist not Set!");
|
||||
return false;
|
||||
}
|
||||
byte[] data = Encoding.UTF8.GetBytes("NET WINS " + wins + " " + adapter);
|
||||
this.net_send.Send(data, data.Length, this.net_send_port);
|
||||
return Boolean.Parse(Encoding.UTF8.GetString(net_gets.Receive(ref net_gets_port)));
|
||||
}
|
||||
|
||||
internal bool setNetworkIpAuto(string adapter)
|
||||
{
|
||||
if (adapter == null)
|
||||
{
|
||||
System.Windows.Forms.MessageBox.Show("Adapter ist not Set!");
|
||||
return false;
|
||||
}
|
||||
byte[] data = Encoding.UTF8.GetBytes("NET IP AUTO "+adapter);
|
||||
this.net_send.Send(data, data.Length, this.net_send_port);
|
||||
return Boolean.Parse(Encoding.UTF8.GetString(net_gets.Receive(ref net_gets_port)));
|
||||
}
|
||||
|
||||
|
||||
internal bool setNetworkDnsAuto(string adapter)
|
||||
{
|
||||
if (adapter == null)
|
||||
{
|
||||
System.Windows.Forms.MessageBox.Show("Adapter ist not Set!");
|
||||
return false;
|
||||
}
|
||||
byte[] data = Encoding.UTF8.GetBytes("NET DNS AUTO " + adapter);
|
||||
this.net_send.Send(data, data.Length, this.net_send_port);
|
||||
return Boolean.Parse(Encoding.UTF8.GetString(net_gets.Receive(ref net_gets_port)));
|
||||
}
|
||||
|
||||
internal bool setNetworkWinsAuto(string adapter)
|
||||
{
|
||||
if (adapter == null)
|
||||
{
|
||||
System.Windows.Forms.MessageBox.Show("Adapter ist not Set!");
|
||||
return false;
|
||||
}
|
||||
byte[] data = Encoding.UTF8.GetBytes("NET WINS AUTO " + adapter);
|
||||
this.net_send.Send(data, data.Length, this.net_send_port);
|
||||
return Boolean.Parse(Encoding.UTF8.GetString(net_gets.Receive(ref net_gets_port)));
|
||||
}
|
||||
}
|
||||
}
|
@ -1,43 +0,0 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
|
||||
namespace NetMonitorConsole
|
||||
{
|
||||
class CMDArgs
|
||||
{
|
||||
private string[] args;
|
||||
public enum Worker
|
||||
{
|
||||
Network,
|
||||
Nothing
|
||||
}
|
||||
private Worker work;
|
||||
public CMDArgs(string[] arg)
|
||||
{
|
||||
this.args = arg;
|
||||
work = Worker.Nothing;
|
||||
setWorker();
|
||||
}
|
||||
|
||||
private void setWorker()
|
||||
{
|
||||
if (args.Length >= 1 && args[0].ToLower() == "-n")
|
||||
work = Worker.Network;
|
||||
}
|
||||
|
||||
|
||||
internal Worker getWorker()
|
||||
{
|
||||
return work;
|
||||
}
|
||||
|
||||
internal string getNetworkName()
|
||||
{
|
||||
if (work == Worker.Network)
|
||||
return args[1];
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
34
NetMonitorConsole/Factory.cs
Normal file
@ -0,0 +1,34 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using BlubbFish.Utils;
|
||||
using NetMonitorUtils;
|
||||
|
||||
namespace NetMonitorConsole
|
||||
{
|
||||
class Factory
|
||||
{
|
||||
private static CmdArgs instanceArguments;
|
||||
private static FileLogger instanceLogger;
|
||||
public static CmdArgs getArguments(string[] args)
|
||||
{
|
||||
if (instanceArguments == null)
|
||||
{
|
||||
instanceArguments = CmdArgs.getInstance(String.Join(" ", args, 0, args.Length));
|
||||
Dictionary<string, CmdArgs.ArgLength> argp = new Dictionary<string, CmdArgs.ArgLength>();
|
||||
argp.Add("-n", CmdArgs.ArgLength.Touple);
|
||||
instanceArguments.setArguments(argp);
|
||||
}
|
||||
return instanceArguments;
|
||||
}
|
||||
public static FileLogger getLogger()
|
||||
{
|
||||
if (instanceLogger == null)
|
||||
{
|
||||
instanceLogger = FileLogger.getInstance("logs/console.log", true);
|
||||
}
|
||||
return instanceLogger;
|
||||
}
|
||||
}
|
||||
}
|
@ -6,36 +6,48 @@
|
||||
<ProductVersion>8.0.30703</ProductVersion>
|
||||
<SchemaVersion>2.0</SchemaVersion>
|
||||
<ProjectGuid>{148AA47C-FA4D-4807-9EB0-5AEAC36C1524}</ProjectGuid>
|
||||
<OutputType>Exe</OutputType>
|
||||
<OutputType>WinExe</OutputType>
|
||||
<AppDesignerFolder>Properties</AppDesignerFolder>
|
||||
<RootNamespace>NetMonitorConsole</RootNamespace>
|
||||
<AssemblyName>NetMonitorConsole</AssemblyName>
|
||||
<TargetFrameworkVersion>v4.0</TargetFrameworkVersion>
|
||||
<TargetFrameworkProfile>Client</TargetFrameworkProfile>
|
||||
<TargetFrameworkVersion>v4.5</TargetFrameworkVersion>
|
||||
<TargetFrameworkProfile>
|
||||
</TargetFrameworkProfile>
|
||||
<FileAlignment>512</FileAlignment>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|x86' ">
|
||||
<PlatformTarget>x86</PlatformTarget>
|
||||
<PlatformTarget>AnyCPU</PlatformTarget>
|
||||
<DebugSymbols>true</DebugSymbols>
|
||||
<DebugType>full</DebugType>
|
||||
<Optimize>false</Optimize>
|
||||
<OutputPath>E:\Programme\NetMonitor\</OutputPath>
|
||||
<OutputPath>..\bin\Debug\</OutputPath>
|
||||
<DefineConstants>DEBUG;TRACE</DefineConstants>
|
||||
<ErrorReport>prompt</ErrorReport>
|
||||
<WarningLevel>4</WarningLevel>
|
||||
<Prefer32Bit>false</Prefer32Bit>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|x86' ">
|
||||
<PlatformTarget>x86</PlatformTarget>
|
||||
<PlatformTarget>AnyCPU</PlatformTarget>
|
||||
<DebugType>pdbonly</DebugType>
|
||||
<Optimize>true</Optimize>
|
||||
<OutputPath>bin\Release\</OutputPath>
|
||||
<DefineConstants>TRACE</DefineConstants>
|
||||
<OutputPath>..\bin\Release\</OutputPath>
|
||||
<DefineConstants>
|
||||
</DefineConstants>
|
||||
<ErrorReport>prompt</ErrorReport>
|
||||
<WarningLevel>4</WarningLevel>
|
||||
<Prefer32Bit>false</Prefer32Bit>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup>
|
||||
<ApplicationIcon>icon.ico</ApplicationIcon>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup>
|
||||
<StartupObject />
|
||||
</PropertyGroup>
|
||||
<ItemGroup>
|
||||
<Reference Include="System" />
|
||||
<Reference Include="System.Core" />
|
||||
<Reference Include="System.Drawing" />
|
||||
<Reference Include="System.Windows.Forms" />
|
||||
<Reference Include="System.Xml.Linq" />
|
||||
<Reference Include="System.Data.DataSetExtensions" />
|
||||
<Reference Include="Microsoft.CSharp" />
|
||||
@ -43,15 +55,38 @@
|
||||
<Reference Include="System.Xml" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Compile Include="CMDArgs.cs" />
|
||||
<Compile Include="Factory.cs" />
|
||||
<Compile Include="Program.cs" />
|
||||
<Compile Include="Properties\AssemblyInfo.cs" />
|
||||
<Compile Include="Properties\Resources.Designer.cs">
|
||||
<AutoGen>True</AutoGen>
|
||||
<DesignTime>True</DesignTime>
|
||||
<DependentUpon>Resources.resx</DependentUpon>
|
||||
</Compile>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\NetMonitorClient\NetMonitorClient.csproj">
|
||||
<Project>{718693A0-06A3-4765-801D-33842861AA61}</Project>
|
||||
<Name>NetMonitorClient</Name>
|
||||
<ProjectReference Include="..\..\Utils\Utils\Utils.csproj">
|
||||
<Project>{fac8ce64-bf13-4ece-8097-aeb5dd060098}</Project>
|
||||
<Name>Utils</Name>
|
||||
</ProjectReference>
|
||||
<ProjectReference Include="..\NetMonitorUtils\NetMonitorUtils.csproj">
|
||||
<Project>{45ee003d-5572-48fe-b90e-6bfe18d9eec8}</Project>
|
||||
<Name>NetMonitorUtils</Name>
|
||||
</ProjectReference>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<None Include="network.ini">
|
||||
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
|
||||
</None>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Content Include="icon.ico" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<EmbeddedResource Include="Properties\Resources.resx">
|
||||
<Generator>ResXFileCodeGenerator</Generator>
|
||||
<LastGenOutput>Resources.Designer.cs</LastGenOutput>
|
||||
</EmbeddedResource>
|
||||
</ItemGroup>
|
||||
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
|
||||
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
|
||||
|
6
NetMonitorConsole/NetMonitorConsole.csproj.user
Normal file
@ -0,0 +1,6 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Debug|x86'">
|
||||
<StartArguments>-n network1</StartArguments>
|
||||
</PropertyGroup>
|
||||
</Project>
|
@ -2,37 +2,69 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using NetMonitorClient;
|
||||
using BlubbFish.Utils;
|
||||
using NetMonitorUtils;
|
||||
using System.Windows.Forms;
|
||||
using System.Drawing;
|
||||
using System.Threading;
|
||||
|
||||
namespace NetMonitorConsole
|
||||
{
|
||||
class Program
|
||||
{
|
||||
private static ServiceControl sc;
|
||||
private static InIReader networkini;
|
||||
private static CMDArgs arg;
|
||||
private static NotifyIcon trayi = new NotifyIcon();
|
||||
static void Main(string[] args)
|
||||
{
|
||||
setNotifyIcon();
|
||||
Console.WriteLine("NetMonitorConsole: Programm zum setzen der Netzwerkeinstellungen");
|
||||
sc = new ServiceControl("NetMonitorServer");
|
||||
networkini = new InIReader("network.ini");
|
||||
arg = new CMDArgs(args);
|
||||
switch (arg.getWorker())
|
||||
if (Factory.getArguments(args).HasArgumentType("-n"))
|
||||
{
|
||||
case CMDArgs.Worker.Network:
|
||||
setNetwork();
|
||||
break;
|
||||
case CMDArgs.Worker.Nothing:
|
||||
Console.WriteLine("usage: NetMonitorConsole.exe: -n [networkid]");
|
||||
break;
|
||||
NetworkSetter netsetter = new NetworkSetter("network.ini", "config.ini");
|
||||
netsetter.eventInfo += netsetter_eventInfo;
|
||||
try
|
||||
{
|
||||
netsetter.setNetwork(Factory.getArguments(args).GetArgumentData("-n"));
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
Console.WriteLine("Fehler: " + e.Message);
|
||||
Thread.Sleep(5000);
|
||||
Factory.getLogger().setLine("### NetMonitorConsole Debug logging dump:");
|
||||
Factory.getLogger().setArray(netsetter.getLog(OwnObject.LogLevel.Debug, true, true).ToArray());
|
||||
showBallonTooltip("NetMonitor Fehler", "Fehler in die Logdatei geschrieben", ToolTipIcon.Warning);
|
||||
Thread.Sleep(5000);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
showBallonTooltip("NetMonitor Fehler", "usage: NetMonitorConsole.exe: -n [networkid]", ToolTipIcon.Error);
|
||||
Thread.Sleep(10000);
|
||||
}
|
||||
trayi.Visible = false;
|
||||
}
|
||||
|
||||
private static void setNetwork()
|
||||
private static void setNotifyIcon()
|
||||
{
|
||||
Networksetter netsetter = new Networksetter(arg.getNetworkName(), networkini, sc);
|
||||
netsetter.setNetwork();
|
||||
Console.WriteLine(String.Join("\n",netsetter.getLog().ToArray()));
|
||||
trayi.Visible = true;
|
||||
trayi.Icon = new Icon(NetMonitorConsole.Properties.Resources.TrayIcon, 40, 40);
|
||||
trayi.Text = "NetMonitorConsole";
|
||||
}
|
||||
|
||||
static void netsetter_eventInfo(string location, string message, OwnObject.LogLevel type, DateTime date)
|
||||
{
|
||||
ToolTipIcon i = ToolTipIcon.None;
|
||||
if (type >= OwnObject.LogLevel.Error) { i = ToolTipIcon.Error; }
|
||||
else if (type >= OwnObject.LogLevel.Warn) { i = ToolTipIcon.Warning; }
|
||||
else { i = ToolTipIcon.Info; }
|
||||
showBallonTooltip("NetMonitor " + type, message, i);
|
||||
}
|
||||
|
||||
private static void showBallonTooltip(string title, string text, ToolTipIcon toolTipIcon)
|
||||
{
|
||||
trayi.BalloonTipIcon = toolTipIcon;
|
||||
trayi.BalloonTipText = text;
|
||||
trayi.BalloonTipTitle = title;
|
||||
trayi.ShowBalloonTip(100);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,16 +1,17 @@
|
||||
using System.Reflection;
|
||||
using System.Runtime.CompilerServices;
|
||||
using System.Runtime.InteropServices;
|
||||
using System.Resources;
|
||||
|
||||
// Allgemeine Informationen über eine Assembly werden über die folgenden
|
||||
// Attribute gesteuert. Ändern Sie diese Attributwerte, um die Informationen zu ändern,
|
||||
// die mit einer Assembly verknüpft sind.
|
||||
[assembly: AssemblyTitle("NetMonitorConsole")]
|
||||
[assembly: AssemblyDescription("")]
|
||||
[assembly: AssemblyDescription("Consolenanwendung zum setzen der Netzwerkeinstellungen")]
|
||||
[assembly: AssemblyConfiguration("")]
|
||||
[assembly: AssemblyCompany("")]
|
||||
[assembly: AssemblyCompany("BlubbFish")]
|
||||
[assembly: AssemblyProduct("NetMonitorConsole")]
|
||||
[assembly: AssemblyCopyright("Copyright © 2010")]
|
||||
[assembly: AssemblyCopyright("Copyright © 2014")]
|
||||
[assembly: AssemblyTrademark("")]
|
||||
[assembly: AssemblyCulture("")]
|
||||
|
||||
@ -32,5 +33,6 @@ using System.Runtime.InteropServices;
|
||||
// Sie können alle Werte angeben oder die standardmäßigen Build- und Revisionsnummern
|
||||
// übernehmen, indem Sie "*" eingeben:
|
||||
// [assembly: AssemblyVersion("1.0.*")]
|
||||
[assembly: AssemblyVersion("1.0.0.0")]
|
||||
[assembly: AssemblyFileVersion("1.0.0.0")]
|
||||
[assembly: AssemblyVersion("1.1.0.0")]
|
||||
[assembly: AssemblyFileVersion("1.1.0.0")]
|
||||
[assembly: NeutralResourcesLanguageAttribute("de-DE")]
|
||||
|
73
NetMonitorConsole/Properties/Resources.Designer.cs
generated
Normal file
@ -0,0 +1,73 @@
|
||||
//------------------------------------------------------------------------------
|
||||
// <auto-generated>
|
||||
// Dieser Code wurde von einem Tool generiert.
|
||||
// Laufzeitversion:4.0.30319.18444
|
||||
//
|
||||
// Änderungen an dieser Datei können falsches Verhalten verursachen und gehen verloren, wenn
|
||||
// der Code erneut generiert wird.
|
||||
// </auto-generated>
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
namespace NetMonitorConsole.Properties {
|
||||
using System;
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Eine stark typisierte Ressourcenklasse zum Suchen von lokalisierten Zeichenfolgen usw.
|
||||
/// </summary>
|
||||
// Diese Klasse wurde von der StronglyTypedResourceBuilder automatisch generiert
|
||||
// -Klasse über ein Tool wie ResGen oder Visual Studio automatisch generiert.
|
||||
// Um einen Member hinzuzufügen oder zu entfernen, bearbeiten Sie die .ResX-Datei und führen dann ResGen
|
||||
// mit der /str-Option erneut aus, oder Sie erstellen Ihr VS-Projekt neu.
|
||||
[global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "4.0.0.0")]
|
||||
[global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
|
||||
[global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()]
|
||||
internal class Resources {
|
||||
|
||||
private static global::System.Resources.ResourceManager resourceMan;
|
||||
|
||||
private static global::System.Globalization.CultureInfo resourceCulture;
|
||||
|
||||
[global::System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")]
|
||||
internal Resources() {
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gibt die zwischengespeicherte ResourceManager-Instanz zurück, die von dieser Klasse verwendet wird.
|
||||
/// </summary>
|
||||
[global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)]
|
||||
internal static global::System.Resources.ResourceManager ResourceManager {
|
||||
get {
|
||||
if (object.ReferenceEquals(resourceMan, null)) {
|
||||
global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("NetMonitorConsole.Properties.Resources", typeof(Resources).Assembly);
|
||||
resourceMan = temp;
|
||||
}
|
||||
return resourceMan;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Überschreibt die CurrentUICulture-Eigenschaft des aktuellen Threads für alle
|
||||
/// Ressourcenzuordnungen, die diese stark typisierte Ressourcenklasse verwenden.
|
||||
/// </summary>
|
||||
[global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)]
|
||||
internal static global::System.Globalization.CultureInfo Culture {
|
||||
get {
|
||||
return resourceCulture;
|
||||
}
|
||||
set {
|
||||
resourceCulture = value;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Sucht eine lokalisierte Ressource vom Typ System.Drawing.Icon ähnlich wie (Symbol).
|
||||
/// </summary>
|
||||
internal static System.Drawing.Icon TrayIcon {
|
||||
get {
|
||||
object obj = ResourceManager.GetObject("TrayIcon", resourceCulture);
|
||||
return ((System.Drawing.Icon)(obj));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
124
NetMonitorConsole/Properties/Resources.resx
Normal file
@ -0,0 +1,124 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<root>
|
||||
<!--
|
||||
Microsoft ResX Schema
|
||||
|
||||
Version 2.0
|
||||
|
||||
The primary goals of this format is to allow a simple XML format
|
||||
that is mostly human readable. The generation and parsing of the
|
||||
various data types are done through the TypeConverter classes
|
||||
associated with the data types.
|
||||
|
||||
Example:
|
||||
|
||||
... ado.net/XML headers & schema ...
|
||||
<resheader name="resmimetype">text/microsoft-resx</resheader>
|
||||
<resheader name="version">2.0</resheader>
|
||||
<resheader name="reader">System.Resources.ResXResourceReader, System.Windows.Forms, ...</resheader>
|
||||
<resheader name="writer">System.Resources.ResXResourceWriter, System.Windows.Forms, ...</resheader>
|
||||
<data name="Name1"><value>this is my long string</value><comment>this is a comment</comment></data>
|
||||
<data name="Color1" type="System.Drawing.Color, System.Drawing">Blue</data>
|
||||
<data name="Bitmap1" mimetype="application/x-microsoft.net.object.binary.base64">
|
||||
<value>[base64 mime encoded serialized .NET Framework object]</value>
|
||||
</data>
|
||||
<data name="Icon1" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
|
||||
<value>[base64 mime encoded string representing a byte array form of the .NET Framework object]</value>
|
||||
<comment>This is a comment</comment>
|
||||
</data>
|
||||
|
||||
There are any number of "resheader" rows that contain simple
|
||||
name/value pairs.
|
||||
|
||||
Each data row contains a name, and value. The row also contains a
|
||||
type or mimetype. Type corresponds to a .NET class that support
|
||||
text/value conversion through the TypeConverter architecture.
|
||||
Classes that don't support this are serialized and stored with the
|
||||
mimetype set.
|
||||
|
||||
The mimetype is used for serialized objects, and tells the
|
||||
ResXResourceReader how to depersist the object. This is currently not
|
||||
extensible. For a given mimetype the value must be set accordingly:
|
||||
|
||||
Note - application/x-microsoft.net.object.binary.base64 is the format
|
||||
that the ResXResourceWriter will generate, however the reader can
|
||||
read any of the formats listed below.
|
||||
|
||||
mimetype: application/x-microsoft.net.object.binary.base64
|
||||
value : The object must be serialized with
|
||||
: System.Runtime.Serialization.Formatters.Binary.BinaryFormatter
|
||||
: and then encoded with base64 encoding.
|
||||
|
||||
mimetype: application/x-microsoft.net.object.soap.base64
|
||||
value : The object must be serialized with
|
||||
: System.Runtime.Serialization.Formatters.Soap.SoapFormatter
|
||||
: and then encoded with base64 encoding.
|
||||
|
||||
mimetype: application/x-microsoft.net.object.bytearray.base64
|
||||
value : The object must be serialized into a byte array
|
||||
: using a System.ComponentModel.TypeConverter
|
||||
: and then encoded with base64 encoding.
|
||||
-->
|
||||
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
|
||||
<xsd:import namespace="http://www.w3.org/XML/1998/namespace" />
|
||||
<xsd:element name="root" msdata:IsDataSet="true">
|
||||
<xsd:complexType>
|
||||
<xsd:choice maxOccurs="unbounded">
|
||||
<xsd:element name="metadata">
|
||||
<xsd:complexType>
|
||||
<xsd:sequence>
|
||||
<xsd:element name="value" type="xsd:string" minOccurs="0" />
|
||||
</xsd:sequence>
|
||||
<xsd:attribute name="name" use="required" type="xsd:string" />
|
||||
<xsd:attribute name="type" type="xsd:string" />
|
||||
<xsd:attribute name="mimetype" type="xsd:string" />
|
||||
<xsd:attribute ref="xml:space" />
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
<xsd:element name="assembly">
|
||||
<xsd:complexType>
|
||||
<xsd:attribute name="alias" type="xsd:string" />
|
||||
<xsd:attribute name="name" type="xsd:string" />
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
<xsd:element name="data">
|
||||
<xsd:complexType>
|
||||
<xsd:sequence>
|
||||
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
|
||||
<xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
|
||||
</xsd:sequence>
|
||||
<xsd:attribute name="name" type="xsd:string" use="required" msdata:Ordinal="1" />
|
||||
<xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
|
||||
<xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
|
||||
<xsd:attribute ref="xml:space" />
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
<xsd:element name="resheader">
|
||||
<xsd:complexType>
|
||||
<xsd:sequence>
|
||||
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
|
||||
</xsd:sequence>
|
||||
<xsd:attribute name="name" type="xsd:string" use="required" />
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
</xsd:choice>
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
</xsd:schema>
|
||||
<resheader name="resmimetype">
|
||||
<value>text/microsoft-resx</value>
|
||||
</resheader>
|
||||
<resheader name="version">
|
||||
<value>2.0</value>
|
||||
</resheader>
|
||||
<resheader name="reader">
|
||||
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||
</resheader>
|
||||
<resheader name="writer">
|
||||
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||
</resheader>
|
||||
<assembly alias="System.Windows.Forms" name="System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" />
|
||||
<data name="TrayIcon" type="System.Resources.ResXFileRef, System.Windows.Forms">
|
||||
<value>..\icon.ico;System.Drawing.Icon, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>
|
||||
</data>
|
||||
</root>
|
BIN
NetMonitorConsole/icon.ico
Normal file
After Width: | Height: | Size: 5.3 KiB |
BIN
NetMonitorConsole/icon.png
Normal file
After Width: | Height: | Size: 1.8 KiB |
6
NetMonitorConsole/network.ini
Normal file
@ -0,0 +1,6 @@
|
||||
[network1]
|
||||
Name=Home
|
||||
Ip=auto
|
||||
Dns=auto
|
||||
Wins=auto
|
||||
Adapter=LAN-Verbindung
|
29
NetMonitorServer/ActionClass.cs
Normal file
@ -0,0 +1,29 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Net.Sockets;
|
||||
using System.Net;
|
||||
|
||||
namespace NetMonitorServer
|
||||
{
|
||||
abstract class ActionClass
|
||||
{
|
||||
protected UdpClient outputNetworkStream;
|
||||
protected IPEndPoint outputNetworkPort;
|
||||
internal void SetAnswerStream(UdpClient udpClient, IPEndPoint iPEndPoint)
|
||||
{
|
||||
this.outputNetworkStream = udpClient;
|
||||
this.outputNetworkPort = iPEndPoint;
|
||||
}
|
||||
|
||||
abstract internal bool Run(Queue<string> arguments);
|
||||
|
||||
protected void sendMessage(string message)
|
||||
{
|
||||
Console.WriteLine(message);
|
||||
byte[] answ = Encoding.UTF8.GetBytes(message);
|
||||
outputNetworkStream.Send(answ, answ.Length, outputNetworkPort);
|
||||
}
|
||||
}
|
||||
}
|
151
NetMonitorServer/Actions/SetNetworks.cs
Normal file
@ -0,0 +1,151 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Diagnostics;
|
||||
using System.Net;
|
||||
using System.Net.Sockets;
|
||||
|
||||
namespace NetMonitorServer
|
||||
{
|
||||
class SetNetworks : ActionClass
|
||||
{
|
||||
private bool setNetworkWins(Queue<string> data)
|
||||
{
|
||||
if (data.Count != 2)
|
||||
{
|
||||
this.sendMessage("To less arguments for SetNetworks.setNetworkWins class");
|
||||
return false;
|
||||
}
|
||||
string ip = data.Dequeue();
|
||||
string name = data.Dequeue();
|
||||
string netsh = "interface ipv4 set winsservers name=\"" + name + (ip == "auto" ? "\" source=dhcp" : "\" static " + ip);
|
||||
try
|
||||
{
|
||||
this.runProgramNetsh(netsh);
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
this.sendMessage(e.Message);
|
||||
return false;
|
||||
}
|
||||
this.sendMessage("true");
|
||||
return true;
|
||||
}
|
||||
|
||||
private bool setNetworkDns(Queue<string> data)
|
||||
{
|
||||
if (data.Count != 2)
|
||||
{
|
||||
this.sendMessage("To less arguments for SetNetworks.setNetworkDns class");
|
||||
return false;
|
||||
}
|
||||
string ip = data.Dequeue();
|
||||
string name = data.Dequeue();
|
||||
string netsh = "interface ipv4 set dnsservers name=\"" + name + (ip == "auto" ? "\" source=dhcp" : "\" static " + ip + "primary");
|
||||
try
|
||||
{
|
||||
this.runProgramNetsh(netsh);
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
this.sendMessage(e.Message);
|
||||
return false;
|
||||
}
|
||||
this.sendMessage("true");
|
||||
return true;
|
||||
}
|
||||
|
||||
private bool setNetworkIp(Queue<string> data)
|
||||
{
|
||||
if (data.Count != 2 && data.Count != 4)
|
||||
{
|
||||
this.sendMessage("To less arguments for SetNetworks.setNetworkIp class");
|
||||
return false;
|
||||
}
|
||||
string ip = data.Dequeue();
|
||||
string netsh = "";
|
||||
if (ip == "auto")
|
||||
{
|
||||
string name = data.Dequeue();
|
||||
netsh = "interface ipv4 set address name=\"" + name + "\" source=dhcp";
|
||||
}
|
||||
else
|
||||
{
|
||||
string subnet = data.Dequeue();
|
||||
string gw = data.Dequeue();
|
||||
string name = data.Dequeue();
|
||||
netsh = "interface ipv4 set address \"" + name + "\" static " + ip + " " + subnet + " " + gw;
|
||||
}
|
||||
try
|
||||
{
|
||||
this.runProgramNetsh(netsh);
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
this.sendMessage(e.Message);
|
||||
return false;
|
||||
}
|
||||
this.sendMessage("true");
|
||||
return true;
|
||||
}
|
||||
|
||||
private bool setNetworkAuto(Queue<string> data)
|
||||
{
|
||||
if (data.Count != 1)
|
||||
{
|
||||
this.sendMessage("To less arguments for SetNetworks.setNetworkDns class");
|
||||
return false;
|
||||
}
|
||||
string name = data.Dequeue();
|
||||
try
|
||||
{
|
||||
this.runProgramNetsh("interface ipv4 set address name=\"" + name + "\" source=dhcp");
|
||||
this.runProgramNetsh("interface ipv4 set dnsservers name=\"" + name + "\" source=dhcp");
|
||||
this.runProgramNetsh("interface ipv4 set winsservers name=\"" + name + "\" source=dhcp");
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
this.sendMessage(e.Message);
|
||||
return false;
|
||||
}
|
||||
this.sendMessage("true");
|
||||
return true;
|
||||
}
|
||||
|
||||
private bool runProgramNetsh(string args)
|
||||
{
|
||||
Process p = new Process();
|
||||
p.StartInfo.Arguments = args;
|
||||
p.StartInfo.FileName = "netsh";
|
||||
p.StartInfo.CreateNoWindow = true;
|
||||
p.StartInfo.RedirectStandardOutput = true;
|
||||
p.StartInfo.UseShellExecute = false;
|
||||
p.Start();
|
||||
string output = p.StandardOutput.ReadToEnd();
|
||||
p.WaitForExit();
|
||||
Console.WriteLine(output.Trim());
|
||||
if (p.ExitCode == 0)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
throw new Exception(output.Trim());
|
||||
}
|
||||
internal override bool Run(Queue<string> arguments)
|
||||
{
|
||||
if (arguments.Count < 2)
|
||||
{
|
||||
this.sendMessage("To less arguments for SetNetwork class");
|
||||
return false;
|
||||
}
|
||||
switch (arguments.Dequeue().ToLower())
|
||||
{
|
||||
case "auto": return this.setNetworkAuto(arguments);
|
||||
case "ip": return this.setNetworkIp(arguments);
|
||||
case "dns": return this.setNetworkDns(arguments);
|
||||
case "wins": return this.setNetworkWins(arguments);
|
||||
default: this.sendMessage("Wrong arguments for service on SetNetwork class"); return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
15
NetMonitorServer/Actions/SetOpenVPNService.cs
Normal file
@ -0,0 +1,15 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
|
||||
namespace NetMonitorServer
|
||||
{
|
||||
class SetOpenVPNService : ActionClass
|
||||
{
|
||||
internal override bool Run(Queue<string> arguments)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
}
|
||||
}
|
115
NetMonitorServer/Actions/SetService.cs
Normal file
@ -0,0 +1,115 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Diagnostics;
|
||||
using System.Net;
|
||||
using System.Net.Sockets;
|
||||
using System.ServiceProcess;
|
||||
|
||||
namespace NetMonitorServer
|
||||
{
|
||||
class SetService : ActionClass
|
||||
{
|
||||
ServiceController serviceController;
|
||||
|
||||
private bool setServiceStart(Queue<string> data)
|
||||
{
|
||||
if (data.Count != 1)
|
||||
{
|
||||
this.sendMessage("To less arguments for SetService.setServiceStart class");
|
||||
return false;
|
||||
}
|
||||
this.serviceController.ServiceName = data.Dequeue();
|
||||
try
|
||||
{
|
||||
this.serviceController.Start();
|
||||
this.serviceController.WaitForStatus(ServiceControllerStatus.Running, new TimeSpan(0, 0, 30));
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
this.sendMessage(e.Message);
|
||||
return false;
|
||||
}
|
||||
if (this.serviceController.Status == ServiceControllerStatus.Running)
|
||||
{
|
||||
this.sendMessage("true");
|
||||
}
|
||||
else
|
||||
{
|
||||
this.sendMessage("The service isn't started");
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
private bool setServiceStop(Queue<string> data)
|
||||
{
|
||||
if (data.Count != 1)
|
||||
{
|
||||
this.sendMessage("To less arguments for SetService.setServiceStop class");
|
||||
return false;
|
||||
}
|
||||
this.serviceController.ServiceName = data.Dequeue();
|
||||
try
|
||||
{
|
||||
this.serviceController.Stop();
|
||||
this.serviceController.WaitForStatus(ServiceControllerStatus.Stopped, new TimeSpan(0, 0, 30));
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
this.sendMessage(e.Message);
|
||||
return false;
|
||||
}
|
||||
if (this.serviceController.Status == ServiceControllerStatus.Stopped)
|
||||
{
|
||||
this.sendMessage("true");
|
||||
}
|
||||
else
|
||||
{
|
||||
this.sendMessage("The service isn't stopped");
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
private bool getServiceStatus(Queue<string> data)
|
||||
{
|
||||
if (data.Count != 1)
|
||||
{
|
||||
this.sendMessage("To less arguments for SetService.setServiceStatus class");
|
||||
return false;
|
||||
}
|
||||
try
|
||||
{
|
||||
this.serviceController.ServiceName = data.Dequeue();
|
||||
if (this.serviceController.Status == ServiceControllerStatus.Running)
|
||||
this.sendMessage("running");
|
||||
else
|
||||
this.sendMessage("stopped");
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
this.sendMessage(e.Message);
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
internal override bool Run(Queue<string> arguments)
|
||||
{
|
||||
if (arguments.Count != 2)
|
||||
{
|
||||
this.sendMessage("To less arguments for SetService class");
|
||||
return false;
|
||||
}
|
||||
this.serviceController = new ServiceController();
|
||||
switch (arguments.Dequeue().ToLower())
|
||||
{
|
||||
case "start": return this.setServiceStart(arguments);
|
||||
case "stop": return this.setServiceStop(arguments);
|
||||
case "status": return this.getServiceStatus(arguments);
|
||||
default: this.sendMessage("Wrong arguments for service on SetService class"); return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
25
NetMonitorServer/Factory.cs
Normal file
@ -0,0 +1,25 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using BlubbFish.Utils;
|
||||
|
||||
namespace NetMonitorServer
|
||||
{
|
||||
class Factory
|
||||
{
|
||||
internal static ActionClass getAction(string className)
|
||||
{
|
||||
if (className.Substring(0, 3).ToLower() == "net")
|
||||
return new SetNetworks();
|
||||
if (className.Substring(0, 7).ToLower() == "service")
|
||||
return new SetService();
|
||||
if (className.Substring(0, 7).ToLower() == "openvpn")
|
||||
return new SetOpenVPNService();
|
||||
return null;
|
||||
}
|
||||
internal static InIReader getSettings() {
|
||||
return InIReader.getInstance("config.ini");
|
||||
}
|
||||
}
|
||||
}
|
@ -1,6 +1,6 @@
|
||||
namespace NetMonitorServer
|
||||
{
|
||||
partial class Service1
|
||||
partial class MainService
|
||||
{
|
||||
/// <summary>
|
||||
/// Required designer variable.
|
||||
@ -28,10 +28,8 @@
|
||||
/// </summary>
|
||||
private void InitializeComponent()
|
||||
{
|
||||
this.components = new System.ComponentModel.Container();
|
||||
this.timer1 = new System.Windows.Forms.Timer(this.components);
|
||||
//
|
||||
// Service1
|
||||
// MainService
|
||||
//
|
||||
this.ServiceName = "NetMonitorServer";
|
||||
|
||||
@ -39,6 +37,5 @@
|
||||
|
||||
#endregion
|
||||
|
||||
private System.Windows.Forms.Timer timer1;
|
||||
}
|
||||
}
|
84
NetMonitorServer/MainService.cs
Normal file
@ -0,0 +1,84 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel;
|
||||
using System.Data;
|
||||
using System.Diagnostics;
|
||||
using System.Linq;
|
||||
using System.ServiceProcess;
|
||||
using System.Text;
|
||||
using System.Net;
|
||||
using System.Net.Sockets;
|
||||
using System.Threading;
|
||||
using BlubbFish.Utils;
|
||||
|
||||
namespace NetMonitorServer
|
||||
{
|
||||
public partial class MainService : ServiceBase
|
||||
{
|
||||
private Thread serverThread = new Thread(new ThreadStart(overwatch));
|
||||
private static UdpClient receiveStream;
|
||||
public MainService()
|
||||
{
|
||||
InitializeComponent();
|
||||
this.serverThread.IsBackground = true;
|
||||
}
|
||||
|
||||
private static void overwatch()
|
||||
{
|
||||
IPEndPoint networkStreamAddress = new IPEndPoint(IPAddress.Loopback, 0);
|
||||
while (true)
|
||||
{
|
||||
if (Thread.CurrentThread.ThreadState == System.Threading.ThreadState.AbortRequested)
|
||||
{
|
||||
receiveStream.Close();
|
||||
break;
|
||||
}
|
||||
byte[] data = receiveStream.Receive(ref networkStreamAddress);
|
||||
Thread queryThread = new Thread(new ParameterizedThreadStart(ServerCommandProcessor));
|
||||
queryThread.Start(data);
|
||||
}
|
||||
}
|
||||
|
||||
private static void ServerCommandProcessor(object threadParam)
|
||||
{
|
||||
string data = Encoding.UTF8.GetString((byte[])threadParam);
|
||||
Console.WriteLine(data);
|
||||
Queue<string> arguments = new Queue<string>(data.Split(' '));
|
||||
if (arguments.Count < 2)
|
||||
{
|
||||
Console.WriteLine("Zu wenig Argumente");
|
||||
return;
|
||||
}
|
||||
ActionClass a = Factory.getAction(arguments.Dequeue());
|
||||
if (a == null)
|
||||
{
|
||||
Console.WriteLine("Falsche Angabe der ActionClass");
|
||||
return;
|
||||
}
|
||||
a.SetAnswerStream(new UdpClient(), new IPEndPoint(IPAddress.Loopback, Int32.Parse(arguments.Dequeue())));
|
||||
a.Run(arguments);
|
||||
}
|
||||
|
||||
protected override void OnStart(string[] args)
|
||||
{
|
||||
this.initServerThread();
|
||||
this.serverThread.Start();
|
||||
}
|
||||
|
||||
private void initServerThread()
|
||||
{
|
||||
receiveStream = new UdpClient(Int32.Parse(Factory.getSettings().getValue("ports", "server")));
|
||||
}
|
||||
|
||||
protected override void OnStop()
|
||||
{
|
||||
this.serverThread.Abort();
|
||||
try { receiveStream.Close(); } catch { };
|
||||
}
|
||||
|
||||
public void StartServiceConsole(string[] args)
|
||||
{
|
||||
this.OnStart(args);
|
||||
}
|
||||
}
|
||||
}
|
@ -117,12 +117,6 @@
|
||||
<resheader name="writer">
|
||||
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||
</resheader>
|
||||
<metadata name="timer1.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
|
||||
<value>143, 71</value>
|
||||
</metadata>
|
||||
<metadata name="serviceController1.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
|
||||
<value>230, 71</value>
|
||||
</metadata>
|
||||
<metadata name="$this.TrayLargeIcon" type="System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
|
||||
<value>False</value>
|
||||
</metadata>
|
@ -6,32 +6,42 @@
|
||||
<ProductVersion>8.0.30703</ProductVersion>
|
||||
<SchemaVersion>2.0</SchemaVersion>
|
||||
<ProjectGuid>{7813196F-D729-44A2-81C7-82BB83E207F5}</ProjectGuid>
|
||||
<OutputType>WinExe</OutputType>
|
||||
<OutputType>Exe</OutputType>
|
||||
<AppDesignerFolder>Properties</AppDesignerFolder>
|
||||
<RootNamespace>NetMonitorServer</RootNamespace>
|
||||
<AssemblyName>NetMonitorServer</AssemblyName>
|
||||
<TargetFrameworkVersion>v4.0</TargetFrameworkVersion>
|
||||
<TargetFrameworkProfile>Client</TargetFrameworkProfile>
|
||||
<TargetFrameworkVersion>v4.5</TargetFrameworkVersion>
|
||||
<TargetFrameworkProfile>
|
||||
</TargetFrameworkProfile>
|
||||
<FileAlignment>512</FileAlignment>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|x86' ">
|
||||
<PlatformTarget>x86</PlatformTarget>
|
||||
<PlatformTarget>AnyCPU</PlatformTarget>
|
||||
<DebugSymbols>true</DebugSymbols>
|
||||
<DebugType>full</DebugType>
|
||||
<Optimize>false</Optimize>
|
||||
<OutputPath>E:\Programme\NetMonitor\</OutputPath>
|
||||
<OutputPath>..\bin\Debug\</OutputPath>
|
||||
<DefineConstants>DEBUG;TRACE</DefineConstants>
|
||||
<ErrorReport>prompt</ErrorReport>
|
||||
<WarningLevel>4</WarningLevel>
|
||||
<Prefer32Bit>false</Prefer32Bit>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|x86' ">
|
||||
<PlatformTarget>x86</PlatformTarget>
|
||||
<DebugType>pdbonly</DebugType>
|
||||
<PlatformTarget>AnyCPU</PlatformTarget>
|
||||
<DebugType>none</DebugType>
|
||||
<Optimize>true</Optimize>
|
||||
<OutputPath>E:\Programme\NetMonitor\</OutputPath>
|
||||
<DefineConstants>TRACE</DefineConstants>
|
||||
<OutputPath>..\bin\Release\</OutputPath>
|
||||
<DefineConstants>
|
||||
</DefineConstants>
|
||||
<ErrorReport>prompt</ErrorReport>
|
||||
<WarningLevel>4</WarningLevel>
|
||||
<Prefer32Bit>false</Prefer32Bit>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup>
|
||||
<ApplicationIcon>icon.ico</ApplicationIcon>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup>
|
||||
<StartupObject />
|
||||
</PropertyGroup>
|
||||
<ItemGroup>
|
||||
<Reference Include="System" />
|
||||
@ -46,24 +56,43 @@
|
||||
<Reference Include="System.Xml" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Compile Include="SetService.cs" />
|
||||
<Compile Include="Service1.cs">
|
||||
<Compile Include="ActionClass.cs" />
|
||||
<Compile Include="Factory.cs" />
|
||||
<Compile Include="Actions\SetOpenVPNService.cs" />
|
||||
<Compile Include="Actions\SetService.cs" />
|
||||
<Compile Include="MainService.cs">
|
||||
<SubType>Component</SubType>
|
||||
</Compile>
|
||||
<Compile Include="Service1.Designer.cs">
|
||||
<DependentUpon>Service1.cs</DependentUpon>
|
||||
<Compile Include="MainService.Designer.cs">
|
||||
<DependentUpon>MainService.cs</DependentUpon>
|
||||
</Compile>
|
||||
<Compile Include="Program.cs">
|
||||
<SubType>Component</SubType>
|
||||
</Compile>
|
||||
<Compile Include="Properties\AssemblyInfo.cs" />
|
||||
<Compile Include="SetNetworks.cs" />
|
||||
<Compile Include="Actions\SetNetworks.cs" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<EmbeddedResource Include="Service1.resx">
|
||||
<DependentUpon>Service1.cs</DependentUpon>
|
||||
<EmbeddedResource Include="MainService.resx">
|
||||
<DependentUpon>MainService.cs</DependentUpon>
|
||||
</EmbeddedResource>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<None Include="app.config" />
|
||||
<None Include="ClassDiagram1.cd" />
|
||||
<None Include="config.ini">
|
||||
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
|
||||
</None>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Content Include="icon.ico" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\..\Utils\Utils\Utils.csproj">
|
||||
<Project>{fac8ce64-bf13-4ece-8097-aeb5dd060098}</Project>
|
||||
<Name>Utils</Name>
|
||||
</ProjectReference>
|
||||
</ItemGroup>
|
||||
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
|
||||
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
|
||||
Other similar extension points exist, see Microsoft.Common.targets.
|
||||
|
@ -8,52 +8,52 @@ using System.ComponentModel;
|
||||
|
||||
namespace NetMonitorServer
|
||||
{
|
||||
[RunInstaller(true)]
|
||||
public class TestWinInstaller : Installer
|
||||
{
|
||||
private ServiceInstaller m_ThisService;
|
||||
private ServiceProcessInstaller m_ThisServiceProcess;
|
||||
[RunInstaller(true)]
|
||||
public class TestWinInstaller : Installer
|
||||
{
|
||||
private ServiceInstaller m_ThisService;
|
||||
private ServiceProcessInstaller m_ThisServiceProcess;
|
||||
|
||||
public TestWinInstaller()
|
||||
{
|
||||
m_ThisService = new ServiceInstaller();
|
||||
m_ThisServiceProcess = new ServiceProcessInstaller();
|
||||
public TestWinInstaller()
|
||||
{
|
||||
m_ThisService = new ServiceInstaller();
|
||||
m_ThisServiceProcess = new ServiceProcessInstaller();
|
||||
|
||||
m_ThisServiceProcess.Account = ServiceAccount.LocalSystem;
|
||||
m_ThisService.ServiceName = "NetMonitorServer";
|
||||
m_ThisService.StartType = ServiceStartMode.Automatic;
|
||||
m_ThisService.Description = "Teil von NetMonitor der die Systemnahen Befele ausführt";
|
||||
m_ThisService.DisplayName = "Netzwerk Settings Tool";
|
||||
m_ThisServiceProcess.Account = ServiceAccount.LocalSystem;
|
||||
m_ThisService.ServiceName = "NetMonitorServer";
|
||||
m_ThisService.StartType = ServiceStartMode.Automatic;
|
||||
m_ThisService.Description = "Teil von NetMonitor der die Systemnahen Befele ausführt";
|
||||
m_ThisService.DisplayName = "Netzwerk Settings Tool";
|
||||
|
||||
Installers.Add(m_ThisService);
|
||||
Installers.Add(m_ThisServiceProcess);
|
||||
}
|
||||
}
|
||||
static class Program
|
||||
{
|
||||
/// <summary>
|
||||
/// The main entry point for the application.
|
||||
/// </summary>
|
||||
static void Main(string[] args)
|
||||
{
|
||||
if (args.Length == 0)
|
||||
{
|
||||
ServiceBase[] ServicesToRun;
|
||||
ServicesToRun = new ServiceBase[]
|
||||
{
|
||||
new Service1()
|
||||
};
|
||||
ServiceBase.Run(ServicesToRun);
|
||||
}
|
||||
else if (args.Length == 1 || args[0] == "-r")
|
||||
{
|
||||
Service1 s = new Service1();
|
||||
s.StartServiceConsole(args);
|
||||
while (true)
|
||||
{
|
||||
System.Threading.Thread.Sleep(100);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Installers.Add(m_ThisService);
|
||||
Installers.Add(m_ThisServiceProcess);
|
||||
}
|
||||
}
|
||||
static class Program
|
||||
{
|
||||
/// <summary>
|
||||
/// The main entry point for the application.
|
||||
/// </summary>
|
||||
static void Main(string[] args)
|
||||
{
|
||||
if (args.Length == 0)
|
||||
{
|
||||
ServiceBase[] ServicesToRun;
|
||||
ServicesToRun = new ServiceBase[]
|
||||
{
|
||||
new MainService()
|
||||
};
|
||||
ServiceBase.Run(ServicesToRun);
|
||||
}
|
||||
else if (args.Length == 1 || args[0] == "-r")
|
||||
{
|
||||
MainService s = new MainService();
|
||||
s.StartServiceConsole(args);
|
||||
while (true)
|
||||
{
|
||||
System.Threading.Thread.Sleep(100);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,16 +1,17 @@
|
||||
using System.Reflection;
|
||||
using System.Runtime.CompilerServices;
|
||||
using System.Runtime.InteropServices;
|
||||
using System.Resources;
|
||||
|
||||
// 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("NetMonitorServer")]
|
||||
[assembly: AssemblyDescription("")]
|
||||
[assembly: AssemblyDescription("Server des NetMonitors")]
|
||||
[assembly: AssemblyConfiguration("")]
|
||||
[assembly: AssemblyCompany("")]
|
||||
[assembly: AssemblyCompany("BlubbFish")]
|
||||
[assembly: AssemblyProduct("NetMonitorServer")]
|
||||
[assembly: AssemblyCopyright("Copyright © 2010")]
|
||||
[assembly: AssemblyCopyright("Copyright © 2014")]
|
||||
[assembly: AssemblyTrademark("")]
|
||||
[assembly: AssemblyCulture("")]
|
||||
|
||||
@ -32,5 +33,6 @@ using System.Runtime.InteropServices;
|
||||
// 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")]
|
||||
[assembly: AssemblyVersion("1.1.0.0")]
|
||||
[assembly: AssemblyFileVersion("1.1.0.0")]
|
||||
[assembly: NeutralResourcesLanguageAttribute("de-DE")]
|
||||
|
@ -1,65 +0,0 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel;
|
||||
using System.Data;
|
||||
using System.Diagnostics;
|
||||
using System.Linq;
|
||||
using System.ServiceProcess;
|
||||
using System.Text;
|
||||
using System.Net;
|
||||
using System.Net.Sockets;
|
||||
using System.Threading;
|
||||
|
||||
namespace NetMonitorServer
|
||||
{
|
||||
public partial class Service1 : ServiceBase
|
||||
{
|
||||
private Thread ot;
|
||||
public Service1()
|
||||
{
|
||||
InitializeComponent();
|
||||
this.ot = new Thread(new ThreadStart(overwatch));
|
||||
this.ot.IsBackground = true;
|
||||
}
|
||||
private static void overwatch()
|
||||
{
|
||||
UdpClient net_gets = new UdpClient(34523);
|
||||
IPEndPoint net_gets_port = new IPEndPoint(IPAddress.Loopback, 0);
|
||||
while (true)
|
||||
{
|
||||
if (Thread.CurrentThread.ThreadState == System.Threading.ThreadState.AbortRequested)
|
||||
{
|
||||
net_gets.Close();
|
||||
break;
|
||||
}
|
||||
byte[] data = net_gets.Receive(ref net_gets_port);
|
||||
string text = Encoding.UTF8.GetString(data);
|
||||
switchCommand(text);
|
||||
}
|
||||
}
|
||||
|
||||
private static void switchCommand(string data)
|
||||
{
|
||||
Console.WriteLine(data);
|
||||
if (data.Substring(0, 3).ToLower() == "net")
|
||||
new SetNetworks(data);
|
||||
if (data.Substring(0, 7).ToLower() == "service")
|
||||
new SetService(data);
|
||||
}
|
||||
|
||||
protected override void OnStart(string[] args)
|
||||
{
|
||||
this.ot.Start();
|
||||
}
|
||||
|
||||
protected override void OnStop()
|
||||
{
|
||||
this.ot.Abort();
|
||||
}
|
||||
|
||||
public void StartServiceConsole(string[] args)
|
||||
{
|
||||
this.OnStart(args);
|
||||
}
|
||||
}
|
||||
}
|
@ -1,102 +0,0 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Diagnostics;
|
||||
using System.Net;
|
||||
using System.Net.Sockets;
|
||||
|
||||
namespace NetMonitorServer
|
||||
{
|
||||
class SetNetworks
|
||||
{
|
||||
UdpClient net_send = new UdpClient();
|
||||
IPEndPoint net_send_port = new IPEndPoint(IPAddress.Parse("127.0.0.1"), 34524);
|
||||
|
||||
public SetNetworks(string data)
|
||||
{
|
||||
if (data.Substring(0, 8).ToLower() == "net auto")
|
||||
this.setNetworkAuto(data);
|
||||
if (data.Substring(0, 6).ToLower() == "net ip")
|
||||
this.setNetworkIp(data);
|
||||
if (data.Substring(0, 7).ToLower() == "net dns")
|
||||
this.setNetworkDns(data);
|
||||
if (data.Substring(0, 8).ToLower() == "net wins")
|
||||
this.setNetworkWins(data);
|
||||
}
|
||||
|
||||
private void setNetworkWins(string data)
|
||||
{
|
||||
String[] par = data.Split(' ');
|
||||
if (par.Length != 4)
|
||||
return;
|
||||
bool ret;
|
||||
if (par[2].ToLower() == "auto")
|
||||
ret = this.runProgramNetsh("interface ipv4 set winsservers name=\"" + par[3] + "\" source=dhcp");
|
||||
else
|
||||
ret = this.runProgramNetsh("interface ipv4 set winsservers \"" + par[3] + "\" static " + par[2]);
|
||||
byte[] answ = Encoding.UTF8.GetBytes(ret.ToString());
|
||||
net_send.Send(answ, answ.Length, net_send_port);
|
||||
}
|
||||
|
||||
private void setNetworkDns(string data)
|
||||
{
|
||||
String[] par = data.Split(' ');
|
||||
if (par.Length != 4)
|
||||
return;
|
||||
bool ret;
|
||||
if (par[2].ToLower() == "auto")
|
||||
ret = this.runProgramNetsh("interface ipv4 set dnsservers name=\"" + par[3] + "\" source=dhcp");
|
||||
else
|
||||
ret = this.runProgramNetsh("interface ipv4 set dnsservers \"" + par[3] + "\" static " + par[2] + " primary");
|
||||
byte[] answ = Encoding.UTF8.GetBytes(ret.ToString());
|
||||
net_send.Send(answ, answ.Length, net_send_port);
|
||||
}
|
||||
|
||||
private void setNetworkIp(string data)
|
||||
{
|
||||
String[] par = data.Split(' ');
|
||||
if (par.Length != 4 && par.Length != 6)
|
||||
return;
|
||||
bool ret;
|
||||
if (par[2].ToLower() == "auto")
|
||||
ret = this.runProgramNetsh("interface ipv4 set address name=\"" + par[3] + "\" source=dhcp");
|
||||
else
|
||||
ret = this.runProgramNetsh("interface ipv4 set address \"" + par[5] + "\" static " + par[2] + " " + par[3] + " " + par[4]);
|
||||
byte[] answ = Encoding.UTF8.GetBytes(ret.ToString());
|
||||
net_send.Send(answ, answ.Length, net_send_port);
|
||||
}
|
||||
|
||||
private void setNetworkAuto(string data)
|
||||
{
|
||||
String[] par = data.Split(' ');
|
||||
if (par.Length != 3)
|
||||
return;
|
||||
byte[] answ;
|
||||
if (this.runProgramNetsh("interface ipv4 set address name=\"" + par[2] + "\" source=dhcp") &&
|
||||
this.runProgramNetsh("interface ipv4 set dnsservers name=\"" + par[2] + "\" source=dhcp") &&
|
||||
this.runProgramNetsh("interface ipv4 set winsservers name=\"" + par[2] + "\" source=dhcp"))
|
||||
answ = Encoding.UTF8.GetBytes(true.ToString());
|
||||
else
|
||||
answ = Encoding.UTF8.GetBytes(false.ToString());
|
||||
net_send.Send(answ, answ.Length, net_send_port);
|
||||
}
|
||||
|
||||
private bool runProgramNetsh(string args)
|
||||
{
|
||||
Process p = new Process();
|
||||
p.StartInfo.Arguments = args;
|
||||
p.StartInfo.FileName = "netsh";
|
||||
p.StartInfo.CreateNoWindow = true;
|
||||
p.StartInfo.RedirectStandardOutput = true;
|
||||
p.StartInfo.UseShellExecute = false;
|
||||
p.Start();
|
||||
string output = p.StandardOutput.ReadToEnd();
|
||||
p.WaitForExit();
|
||||
Console.WriteLine(output.Trim());
|
||||
if (p.ExitCode == 0)
|
||||
return true;
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
@ -1,95 +0,0 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Diagnostics;
|
||||
using System.Net;
|
||||
using System.Net.Sockets;
|
||||
|
||||
namespace NetMonitorServer
|
||||
{
|
||||
class SetService
|
||||
{
|
||||
UdpClient net_send = new UdpClient();
|
||||
IPEndPoint net_send_port = new IPEndPoint(IPAddress.Parse("127.0.0.1"), 34524);
|
||||
System.ServiceProcess.ServiceController serviceController;
|
||||
|
||||
public SetService(string data)
|
||||
{
|
||||
this.serviceController = new System.ServiceProcess.ServiceController();
|
||||
if (data.Substring(0, 13).ToLower() == "service start")
|
||||
this.setServiceStart(data);
|
||||
if (data.Substring(0, 12).ToLower() == "service stop")
|
||||
this.setServiceStop(data);
|
||||
if (data.Substring(0, 14).ToLower() == "service status")
|
||||
this.getServiceStatus(data);
|
||||
}
|
||||
|
||||
private void setServiceStart(string data)
|
||||
{
|
||||
String[] par = data.Split(' ');
|
||||
if (par.Length != 3)
|
||||
return;
|
||||
this.serviceController.ServiceName = par[2];
|
||||
try
|
||||
{
|
||||
this.serviceController.Start();
|
||||
this.serviceController.WaitForStatus(System.ServiceProcess.ServiceControllerStatus.Running, new TimeSpan(0, 0, 30));
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
this.sendStr("false");
|
||||
}
|
||||
if (this.serviceController.Status == System.ServiceProcess.ServiceControllerStatus.Running)
|
||||
this.sendStr("true");
|
||||
else
|
||||
this.sendStr("false");
|
||||
}
|
||||
|
||||
private void setServiceStop(string data)
|
||||
{
|
||||
String[] par = data.Split(' ');
|
||||
if (par.Length != 3)
|
||||
return;
|
||||
this.serviceController.ServiceName = par[2];
|
||||
try
|
||||
{
|
||||
this.serviceController.Stop();
|
||||
this.serviceController.WaitForStatus(System.ServiceProcess.ServiceControllerStatus.Stopped, new TimeSpan(0, 0, 30));
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
this.sendStr("false");
|
||||
}
|
||||
if (this.serviceController.Status == System.ServiceProcess.ServiceControllerStatus.Stopped)
|
||||
this.sendStr("true");
|
||||
else
|
||||
this.sendStr("false");
|
||||
}
|
||||
|
||||
private void getServiceStatus(string data)
|
||||
{
|
||||
String[] par = data.Split(' ');
|
||||
if (par.Length != 3)
|
||||
return;
|
||||
try
|
||||
{
|
||||
this.serviceController.ServiceName = par[2];
|
||||
if (this.serviceController.Status == System.ServiceProcess.ServiceControllerStatus.Running)
|
||||
this.sendStr("true");
|
||||
else
|
||||
this.sendStr("false");
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
this.sendStr("false");
|
||||
}
|
||||
}
|
||||
|
||||
private void sendStr(string p)
|
||||
{
|
||||
byte[] answ = Encoding.UTF8.GetBytes(p);
|
||||
net_send.Send(answ, answ.Length, net_send_port);
|
||||
}
|
||||
}
|
||||
}
|
4
NetMonitorServer/config.ini
Normal file
@ -0,0 +1,4 @@
|
||||
[ports]
|
||||
server=54323
|
||||
client_from=54330
|
||||
client_to=54340
|
BIN
NetMonitorServer/icon.ico
Normal file
After Width: | Height: | Size: 5.3 KiB |
BIN
NetMonitorServer/icon.png
Normal file
After Width: | Height: | Size: 1.0 KiB |
84
NetMonitorTray/Controller/Tray.cs
Normal file
@ -0,0 +1,84 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using System.Windows.Forms;
|
||||
|
||||
namespace NetMonitorTray.Controller
|
||||
{
|
||||
public class Tray
|
||||
{
|
||||
private static View.Tray tray;
|
||||
public Tray()
|
||||
{
|
||||
tray = new View.Tray();
|
||||
}
|
||||
public void view()
|
||||
{
|
||||
Application.Run();
|
||||
}
|
||||
/// <summary>
|
||||
/// User klickt auf den Eintrag Beenden
|
||||
/// </summary>
|
||||
/// <param name="sender"></param>
|
||||
/// <param name="e"></param>
|
||||
internal static void Click_Quit(object sender, EventArgs e)
|
||||
{
|
||||
tray.Dispose();
|
||||
Application.ExitThread();
|
||||
}
|
||||
/// <summary>
|
||||
/// User klick auf einen Eintrag Service Starten/Stoppen
|
||||
/// </summary>
|
||||
/// <param name="sender"></param>
|
||||
/// <param name="e"></param>
|
||||
internal static void Click_Service(object sender, EventArgs e)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
//tray.showError("Fehler beim Starten/Stoppen von Service!");
|
||||
/*switch (((ToolStripMenuItem)sender).Name)
|
||||
{
|
||||
case "StartService": tray.setService(true); break;
|
||||
case "StopService": tray.setService(false); break;
|
||||
}*/
|
||||
}
|
||||
/// <summary>
|
||||
/// User klickt Doppelt auf das TrayIcon
|
||||
/// </summary>
|
||||
/// <param name="sender"></param>
|
||||
/// <param name="e"></param>
|
||||
internal static void Click_Tray(object sender, EventArgs e)
|
||||
{
|
||||
//Doppelklick auf das Trayicon
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
/// <summary>
|
||||
/// User klickt auf den Tray-Ballon
|
||||
/// </summary>
|
||||
/// <param name="sender"></param>
|
||||
/// <param name="e"></param>
|
||||
internal static void Click_Ballon(object sender, EventArgs e)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
/// <summary>
|
||||
/// User klickt auf einen Eintrag Netzwerk
|
||||
/// </summary>
|
||||
/// <param name="sender"></param>
|
||||
/// <param name="e"></param>
|
||||
internal static void Click_Network(object sender, EventArgs e)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
/// <summary>
|
||||
/// User klickt auf den Eintrag Öffnen
|
||||
/// </summary>
|
||||
/// <param name="sender"></param>
|
||||
/// <param name="e"></param>
|
||||
internal static void Click_Open(object sender, EventArgs e)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
}
|
||||
}
|
49
NetMonitorTray/Models/Tray.cs
Normal file
@ -0,0 +1,49 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using System.Windows.Forms;
|
||||
using NetMonitorTray.Properties;
|
||||
using BlubbFish.Utils;
|
||||
|
||||
namespace NetMonitorTray.Model
|
||||
{
|
||||
public class Tray : OwnModel<Tray>
|
||||
{
|
||||
private bool serviceRun;
|
||||
private Tray()
|
||||
{
|
||||
this.init();
|
||||
}
|
||||
private void init()
|
||||
{
|
||||
this.serviceRun = false;
|
||||
}
|
||||
|
||||
internal Dictionary<string, Tuple<string, System.Drawing.Bitmap, bool, bool>> getMenuNetwork()
|
||||
{
|
||||
Dictionary<string, Tuple<string, System.Drawing.Bitmap, bool, bool>> ret = new Dictionary<string, Tuple<string, System.Drawing.Bitmap, bool, bool>>();
|
||||
ret.Add("network1", new Tuple<string, System.Drawing.Bitmap, bool, bool>("Netzwerk Home", null, true, false));
|
||||
ret.Add("network2", new Tuple<string, System.Drawing.Bitmap, bool, bool>("Netzwerk Arbeit", null, true, false));
|
||||
ret.Add("network3", new Tuple<string, System.Drawing.Bitmap, bool, bool>("Netzwerk Test", null, true, false));
|
||||
return ret;
|
||||
}
|
||||
|
||||
internal Dictionary<string, Tuple<string, System.Drawing.Bitmap, bool, bool>> getMenuOpenVpnService()
|
||||
{
|
||||
Dictionary<string, Tuple<string, System.Drawing.Bitmap, bool, bool>> ret = new Dictionary<string, Tuple<string, System.Drawing.Bitmap, bool, bool>>();
|
||||
ret.Add("StartService", new Tuple<string, System.Drawing.Bitmap, bool, bool>("Service Starten", Properties.Resources.MenuImagesServerConnect, !this.serviceRun, !this.serviceRun));
|
||||
ret.Add("StopService", new Tuple<string, System.Drawing.Bitmap, bool, bool>("Service Stoppen", Properties.Resources.MenuImagesServerDisconnect, this.serviceRun, this.serviceRun));
|
||||
return ret;
|
||||
}
|
||||
|
||||
public void setService(bool run)
|
||||
{
|
||||
this.serviceRun = run;
|
||||
this.update();
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
96
NetMonitorTray/NetMonitorTray.csproj
Normal file
@ -0,0 +1,96 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<Project ToolsVersion="4.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
|
||||
<PropertyGroup>
|
||||
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
|
||||
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
|
||||
<ProjectGuid>{0B85C838-3295-4FDA-9B07-4F5B3681BE2F}</ProjectGuid>
|
||||
<OutputType>Exe</OutputType>
|
||||
<AppDesignerFolder>Properties</AppDesignerFolder>
|
||||
<RootNamespace>NetMonitorTray</RootNamespace>
|
||||
<AssemblyName>NetMonitorTray</AssemblyName>
|
||||
<TargetFrameworkVersion>v4.5</TargetFrameworkVersion>
|
||||
<FileAlignment>512</FileAlignment>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
|
||||
<PlatformTarget>AnyCPU</PlatformTarget>
|
||||
<DebugSymbols>true</DebugSymbols>
|
||||
<DebugType>full</DebugType>
|
||||
<Optimize>false</Optimize>
|
||||
<OutputPath>..\bin\Debug\</OutputPath>
|
||||
<DefineConstants>DEBUG;TRACE</DefineConstants>
|
||||
<ErrorReport>prompt</ErrorReport>
|
||||
<WarningLevel>4</WarningLevel>
|
||||
<Prefer32Bit>false</Prefer32Bit>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
|
||||
<PlatformTarget>AnyCPU</PlatformTarget>
|
||||
<DebugType>pdbonly</DebugType>
|
||||
<Optimize>true</Optimize>
|
||||
<OutputPath>..\bin\Release\</OutputPath>
|
||||
<DefineConstants>
|
||||
</DefineConstants>
|
||||
<ErrorReport>prompt</ErrorReport>
|
||||
<WarningLevel>4</WarningLevel>
|
||||
<Prefer32Bit>false</Prefer32Bit>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup>
|
||||
<ApplicationIcon>icon.ico</ApplicationIcon>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup>
|
||||
<StartupObject />
|
||||
</PropertyGroup>
|
||||
<ItemGroup>
|
||||
<Reference Include="System" />
|
||||
<Reference Include="System.Core" />
|
||||
<Reference Include="System.Drawing" />
|
||||
<Reference Include="System.Windows.Forms" />
|
||||
<Reference Include="System.Xml.Linq" />
|
||||
<Reference Include="System.Data.DataSetExtensions" />
|
||||
<Reference Include="Microsoft.CSharp" />
|
||||
<Reference Include="System.Data" />
|
||||
<Reference Include="System.Xml" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Compile Include="Controller\Tray.cs" />
|
||||
<Compile Include="Models\Tray.cs" />
|
||||
<Compile Include="Program.cs" />
|
||||
<Compile Include="Properties\AssemblyInfo.cs" />
|
||||
<Compile Include="Properties\Resources.Designer.cs">
|
||||
<AutoGen>True</AutoGen>
|
||||
<DesignTime>True</DesignTime>
|
||||
<DependentUpon>Resources.resx</DependentUpon>
|
||||
</Compile>
|
||||
<Compile Include="Views\Tray.cs" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Content Include="icon.ico" />
|
||||
<Content Include="Resources\Icons\door_open.png" />
|
||||
<Content Include="Resources\Icons\server_connect.png" />
|
||||
<Content Include="Resources\Icons\server_delete.png" />
|
||||
<Content Include="Resources\working.ico" />
|
||||
<Content Include="Resources\nothing.ico" />
|
||||
<Content Include="Resources\connected.ico" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<EmbeddedResource Include="Properties\Resources.resx">
|
||||
<Generator>ResXFileCodeGenerator</Generator>
|
||||
<LastGenOutput>Resources.Designer.cs</LastGenOutput>
|
||||
</EmbeddedResource>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\..\Utils\Utils\Utils.csproj">
|
||||
<Project>{fac8ce64-bf13-4ece-8097-aeb5dd060098}</Project>
|
||||
<Name>Utils</Name>
|
||||
</ProjectReference>
|
||||
</ItemGroup>
|
||||
<ItemGroup />
|
||||
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
|
||||
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
|
||||
Other similar extension points exist, see Microsoft.Common.targets.
|
||||
<Target Name="BeforeBuild">
|
||||
</Target>
|
||||
<Target Name="AfterBuild">
|
||||
</Target>
|
||||
-->
|
||||
</Project>
|
18
NetMonitorTray/Program.cs
Normal file
@ -0,0 +1,18 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
|
||||
namespace NetMonitorTray
|
||||
{
|
||||
class Program
|
||||
{
|
||||
static void Main(string[] args)
|
||||
{
|
||||
Controller.Tray t = new Controller.Tray();
|
||||
t.view();
|
||||
}
|
||||
}
|
||||
}
|
36
NetMonitorTray/Properties/AssemblyInfo.cs
Normal file
@ -0,0 +1,36 @@
|
||||
using System.Reflection;
|
||||
using System.Runtime.CompilerServices;
|
||||
using System.Runtime.InteropServices;
|
||||
|
||||
// Allgemeine Informationen über eine Assembly werden über die folgenden
|
||||
// Attribute gesteuert. Ändern Sie diese Attributwerte, um die Informationen zu ändern,
|
||||
// die mit einer Assembly verknüpft sind.
|
||||
[assembly: AssemblyTitle("NetMonitorTray")]
|
||||
[assembly: AssemblyDescription("NetMonitor TrayLauncher")]
|
||||
[assembly: AssemblyConfiguration("")]
|
||||
[assembly: AssemblyCompany("BlubbFish")]
|
||||
[assembly: AssemblyProduct("NetMonitorTray")]
|
||||
[assembly: AssemblyCopyright("Copyright © 2014")]
|
||||
[assembly: AssemblyTrademark("")]
|
||||
[assembly: AssemblyCulture("")]
|
||||
|
||||
// Durch Festlegen von ComVisible auf "false" werden die Typen in dieser Assembly unsichtbar
|
||||
// für COM-Komponenten. Wenn Sie auf einen Typ in dieser Assembly von
|
||||
// COM zugreifen müssen, legen Sie das ComVisible-Attribut für diesen Typ auf "true" fest.
|
||||
[assembly: ComVisible(false)]
|
||||
|
||||
// Die folgende GUID bestimmt die ID der Typbibliothek, wenn dieses Projekt für COM verfügbar gemacht wird
|
||||
[assembly: Guid("9069ec73-a0b6-4414-b9f0-e3794324b8bd")]
|
||||
|
||||
// Versionsinformationen für eine Assembly bestehen aus den folgenden vier Werten:
|
||||
//
|
||||
// Hauptversion
|
||||
// Nebenversion
|
||||
// Buildnummer
|
||||
// Revision
|
||||
//
|
||||
// Sie können alle Werte angeben oder die standardmäßigen Build- und Revisionsnummern
|
||||
// übernehmen, indem Sie "*" eingeben:
|
||||
// [assembly: AssemblyVersion("1.0.*")]
|
||||
[assembly: AssemblyVersion("1.0.0.0")]
|
||||
[assembly: AssemblyFileVersion("1.0.0.0")]
|
123
NetMonitorTray/Properties/Resources.Designer.cs
generated
Normal file
@ -0,0 +1,123 @@
|
||||
//------------------------------------------------------------------------------
|
||||
// <auto-generated>
|
||||
// Dieser Code wurde von einem Tool generiert.
|
||||
// Laufzeitversion:4.0.30319.18444
|
||||
//
|
||||
// Änderungen an dieser Datei können falsches Verhalten verursachen und gehen verloren, wenn
|
||||
// der Code erneut generiert wird.
|
||||
// </auto-generated>
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
namespace NetMonitorTray.Properties {
|
||||
using System;
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Eine stark typisierte Ressourcenklasse zum Suchen von lokalisierten Zeichenfolgen usw.
|
||||
/// </summary>
|
||||
// Diese Klasse wurde von der StronglyTypedResourceBuilder automatisch generiert
|
||||
// -Klasse über ein Tool wie ResGen oder Visual Studio automatisch generiert.
|
||||
// Um einen Member hinzuzufügen oder zu entfernen, bearbeiten Sie die .ResX-Datei und führen dann ResGen
|
||||
// mit der /str-Option erneut aus, oder Sie erstellen Ihr VS-Projekt neu.
|
||||
[global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "4.0.0.0")]
|
||||
[global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
|
||||
[global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()]
|
||||
internal class Resources {
|
||||
|
||||
private static global::System.Resources.ResourceManager resourceMan;
|
||||
|
||||
private static global::System.Globalization.CultureInfo resourceCulture;
|
||||
|
||||
[global::System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")]
|
||||
internal Resources() {
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gibt die zwischengespeicherte ResourceManager-Instanz zurück, die von dieser Klasse verwendet wird.
|
||||
/// </summary>
|
||||
[global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)]
|
||||
internal static global::System.Resources.ResourceManager ResourceManager {
|
||||
get {
|
||||
if (object.ReferenceEquals(resourceMan, null)) {
|
||||
global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("NetMonitorTray.Properties.Resources", typeof(Resources).Assembly);
|
||||
resourceMan = temp;
|
||||
}
|
||||
return resourceMan;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Überschreibt die CurrentUICulture-Eigenschaft des aktuellen Threads für alle
|
||||
/// Ressourcenzuordnungen, die diese stark typisierte Ressourcenklasse verwenden.
|
||||
/// </summary>
|
||||
[global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)]
|
||||
internal static global::System.Globalization.CultureInfo Culture {
|
||||
get {
|
||||
return resourceCulture;
|
||||
}
|
||||
set {
|
||||
resourceCulture = value;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Sucht eine lokalisierte Ressource vom Typ System.Drawing.Icon ähnlich wie (Symbol).
|
||||
/// </summary>
|
||||
internal static System.Drawing.Icon IconConnected {
|
||||
get {
|
||||
object obj = ResourceManager.GetObject("IconConnected", resourceCulture);
|
||||
return ((System.Drawing.Icon)(obj));
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Sucht eine lokalisierte Ressource vom Typ System.Drawing.Icon ähnlich wie (Symbol).
|
||||
/// </summary>
|
||||
internal static System.Drawing.Icon IconNothing {
|
||||
get {
|
||||
object obj = ResourceManager.GetObject("IconNothing", resourceCulture);
|
||||
return ((System.Drawing.Icon)(obj));
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Sucht eine lokalisierte Ressource vom Typ System.Drawing.Icon ähnlich wie (Symbol).
|
||||
/// </summary>
|
||||
internal static System.Drawing.Icon IconWorking {
|
||||
get {
|
||||
object obj = ResourceManager.GetObject("IconWorking", resourceCulture);
|
||||
return ((System.Drawing.Icon)(obj));
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Sucht eine lokalisierte Ressource vom Typ System.Drawing.Bitmap.
|
||||
/// </summary>
|
||||
internal static System.Drawing.Bitmap MenuImagesQuit {
|
||||
get {
|
||||
object obj = ResourceManager.GetObject("MenuImagesQuit", resourceCulture);
|
||||
return ((System.Drawing.Bitmap)(obj));
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Sucht eine lokalisierte Ressource vom Typ System.Drawing.Bitmap.
|
||||
/// </summary>
|
||||
internal static System.Drawing.Bitmap MenuImagesServerConnect {
|
||||
get {
|
||||
object obj = ResourceManager.GetObject("MenuImagesServerConnect", resourceCulture);
|
||||
return ((System.Drawing.Bitmap)(obj));
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Sucht eine lokalisierte Ressource vom Typ System.Drawing.Bitmap.
|
||||
/// </summary>
|
||||
internal static System.Drawing.Bitmap MenuImagesServerDisconnect {
|
||||
get {
|
||||
object obj = ResourceManager.GetObject("MenuImagesServerDisconnect", resourceCulture);
|
||||
return ((System.Drawing.Bitmap)(obj));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
139
NetMonitorTray/Properties/Resources.resx
Normal file
@ -0,0 +1,139 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<root>
|
||||
<!--
|
||||
Microsoft ResX Schema
|
||||
|
||||
Version 2.0
|
||||
|
||||
The primary goals of this format is to allow a simple XML format
|
||||
that is mostly human readable. The generation and parsing of the
|
||||
various data types are done through the TypeConverter classes
|
||||
associated with the data types.
|
||||
|
||||
Example:
|
||||
|
||||
... ado.net/XML headers & schema ...
|
||||
<resheader name="resmimetype">text/microsoft-resx</resheader>
|
||||
<resheader name="version">2.0</resheader>
|
||||
<resheader name="reader">System.Resources.ResXResourceReader, System.Windows.Forms, ...</resheader>
|
||||
<resheader name="writer">System.Resources.ResXResourceWriter, System.Windows.Forms, ...</resheader>
|
||||
<data name="Name1"><value>this is my long string</value><comment>this is a comment</comment></data>
|
||||
<data name="Color1" type="System.Drawing.Color, System.Drawing">Blue</data>
|
||||
<data name="Bitmap1" mimetype="application/x-microsoft.net.object.binary.base64">
|
||||
<value>[base64 mime encoded serialized .NET Framework object]</value>
|
||||
</data>
|
||||
<data name="Icon1" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
|
||||
<value>[base64 mime encoded string representing a byte array form of the .NET Framework object]</value>
|
||||
<comment>This is a comment</comment>
|
||||
</data>
|
||||
|
||||
There are any number of "resheader" rows that contain simple
|
||||
name/value pairs.
|
||||
|
||||
Each data row contains a name, and value. The row also contains a
|
||||
type or mimetype. Type corresponds to a .NET class that support
|
||||
text/value conversion through the TypeConverter architecture.
|
||||
Classes that don't support this are serialized and stored with the
|
||||
mimetype set.
|
||||
|
||||
The mimetype is used for serialized objects, and tells the
|
||||
ResXResourceReader how to depersist the object. This is currently not
|
||||
extensible. For a given mimetype the value must be set accordingly:
|
||||
|
||||
Note - application/x-microsoft.net.object.binary.base64 is the format
|
||||
that the ResXResourceWriter will generate, however the reader can
|
||||
read any of the formats listed below.
|
||||
|
||||
mimetype: application/x-microsoft.net.object.binary.base64
|
||||
value : The object must be serialized with
|
||||
: System.Runtime.Serialization.Formatters.Binary.BinaryFormatter
|
||||
: and then encoded with base64 encoding.
|
||||
|
||||
mimetype: application/x-microsoft.net.object.soap.base64
|
||||
value : The object must be serialized with
|
||||
: System.Runtime.Serialization.Formatters.Soap.SoapFormatter
|
||||
: and then encoded with base64 encoding.
|
||||
|
||||
mimetype: application/x-microsoft.net.object.bytearray.base64
|
||||
value : The object must be serialized into a byte array
|
||||
: using a System.ComponentModel.TypeConverter
|
||||
: and then encoded with base64 encoding.
|
||||
-->
|
||||
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
|
||||
<xsd:import namespace="http://www.w3.org/XML/1998/namespace" />
|
||||
<xsd:element name="root" msdata:IsDataSet="true">
|
||||
<xsd:complexType>
|
||||
<xsd:choice maxOccurs="unbounded">
|
||||
<xsd:element name="metadata">
|
||||
<xsd:complexType>
|
||||
<xsd:sequence>
|
||||
<xsd:element name="value" type="xsd:string" minOccurs="0" />
|
||||
</xsd:sequence>
|
||||
<xsd:attribute name="name" use="required" type="xsd:string" />
|
||||
<xsd:attribute name="type" type="xsd:string" />
|
||||
<xsd:attribute name="mimetype" type="xsd:string" />
|
||||
<xsd:attribute ref="xml:space" />
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
<xsd:element name="assembly">
|
||||
<xsd:complexType>
|
||||
<xsd:attribute name="alias" type="xsd:string" />
|
||||
<xsd:attribute name="name" type="xsd:string" />
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
<xsd:element name="data">
|
||||
<xsd:complexType>
|
||||
<xsd:sequence>
|
||||
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
|
||||
<xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
|
||||
</xsd:sequence>
|
||||
<xsd:attribute name="name" type="xsd:string" use="required" msdata:Ordinal="1" />
|
||||
<xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
|
||||
<xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
|
||||
<xsd:attribute ref="xml:space" />
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
<xsd:element name="resheader">
|
||||
<xsd:complexType>
|
||||
<xsd:sequence>
|
||||
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
|
||||
</xsd:sequence>
|
||||
<xsd:attribute name="name" type="xsd:string" use="required" />
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
</xsd:choice>
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
</xsd:schema>
|
||||
<resheader name="resmimetype">
|
||||
<value>text/microsoft-resx</value>
|
||||
</resheader>
|
||||
<resheader name="version">
|
||||
<value>2.0</value>
|
||||
</resheader>
|
||||
<resheader name="reader">
|
||||
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||
</resheader>
|
||||
<resheader name="writer">
|
||||
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||
</resheader>
|
||||
<assembly alias="System.Windows.Forms" name="System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" />
|
||||
<data name="IconConnected" type="System.Resources.ResXFileRef, System.Windows.Forms">
|
||||
<value>..\Resources\connected.ico;System.Drawing.Icon, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>
|
||||
</data>
|
||||
<data name="IconNothing" type="System.Resources.ResXFileRef, System.Windows.Forms">
|
||||
<value>..\Resources\nothing.ico;System.Drawing.Icon, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>
|
||||
</data>
|
||||
<data name="IconWorking" type="System.Resources.ResXFileRef, System.Windows.Forms">
|
||||
<value>..\Resources\working.ico;System.Drawing.Icon, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>
|
||||
</data>
|
||||
<data name="MenuImagesQuit" type="System.Resources.ResXFileRef, System.Windows.Forms">
|
||||
<value>..\Resources\Icons\door_open.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>
|
||||
</data>
|
||||
<data name="MenuImagesServerConnect" type="System.Resources.ResXFileRef, System.Windows.Forms">
|
||||
<value>..\Resources\Icons\server_connect.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>
|
||||
</data>
|
||||
<data name="MenuImagesServerDisconnect" type="System.Resources.ResXFileRef, System.Windows.Forms">
|
||||
<value>..\Resources\Icons\server_delete.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>
|
||||
</data>
|
||||
</root>
|
BIN
NetMonitorTray/Resources/Icons/door_open.png
Normal file
After Width: | Height: | Size: 508 B |
BIN
NetMonitorTray/Resources/Icons/server_connect.png
Normal file
After Width: | Height: | Size: 755 B |
BIN
NetMonitorTray/Resources/Icons/server_delete.png
Normal file
After Width: | Height: | Size: 668 B |
BIN
NetMonitorTray/Resources/connected.ico
Normal file
After Width: | Height: | Size: 3.6 KiB |
BIN
NetMonitorTray/Resources/nothing.ico
Normal file
After Width: | Height: | Size: 3.6 KiB |
BIN
NetMonitorTray/Resources/working.ico
Normal file
After Width: | Height: | Size: 5.3 KiB |
110
NetMonitorTray/Views/Tray.cs
Normal file
@ -0,0 +1,110 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using System.Windows.Forms;
|
||||
using System.Drawing;
|
||||
using NetMonitorTray.Properties;
|
||||
using BlubbFish.Utils;
|
||||
|
||||
namespace NetMonitorTray.View
|
||||
{
|
||||
public class Tray : OwnView
|
||||
{
|
||||
private NotifyIcon trayi;
|
||||
private Dictionary<string, Tuple<string, Bitmap, bool, bool>> menuOpenVpnService;
|
||||
private Dictionary<string, Tuple<string, Bitmap, bool, bool>> menuNetwork;
|
||||
|
||||
public Tray()
|
||||
{
|
||||
this.initIcon();
|
||||
Model.Tray.Instance.setObserver(this);
|
||||
}
|
||||
|
||||
public override void update()
|
||||
{
|
||||
this.menuOpenVpnService = Model.Tray.Instance.getMenuOpenVpnService();
|
||||
this.menuNetwork = Model.Tray.Instance.getMenuNetwork();
|
||||
this.trayi.ContextMenuStrip = this.genMenu();
|
||||
}
|
||||
|
||||
private void initIcon()
|
||||
{
|
||||
this.trayi = new NotifyIcon();
|
||||
this.trayi.Visible = true;
|
||||
this.trayi.Icon = new Icon(Resources.IconNothing, 40, 40);
|
||||
this.trayi.Text = "NetMonitorTray";
|
||||
this.trayi.DoubleClick += Controller.Tray.Click_Tray;
|
||||
this.trayi.BalloonTipClicked += Controller.Tray.Click_Ballon;
|
||||
}
|
||||
|
||||
private ContextMenuStrip genMenu()
|
||||
{
|
||||
ContextMenuStrip menu = new ContextMenuStrip();
|
||||
ToolStripMenuItem m1 = new ToolStripMenuItem("Öffnen");
|
||||
m1.Image = Resources.MenuImagesQuit;
|
||||
m1.Click += Controller.Tray.Click_Open;
|
||||
m1.Name = "Open";
|
||||
menu.Items.Add(m1);
|
||||
menu.Items.Add(new ToolStripSeparator());
|
||||
menu.Items.AddRange(this.genMenuIt(this.menuNetwork, Controller.Tray.Click_Network));
|
||||
menu.Items.Add(new ToolStripSeparator());
|
||||
menu.Items.AddRange(this.genMenuIt(this.menuOpenVpnService, Controller.Tray.Click_Service));
|
||||
menu.Items.Add(new ToolStripSeparator());
|
||||
ToolStripMenuItem m2 = new ToolStripMenuItem("Beenden");
|
||||
m2.Image = Resources.MenuImagesQuit;
|
||||
m2.Click += Controller.Tray.Click_Quit;
|
||||
m2.Name = "Quit";
|
||||
menu.Items.Add(m2);
|
||||
return menu;
|
||||
}
|
||||
|
||||
private ToolStripMenuItem[] genMenuIt(Dictionary<string, Tuple<string, Bitmap, bool, bool>> dictionary, EventHandler ev)
|
||||
{
|
||||
List<ToolStripMenuItem> l = new List<ToolStripMenuItem>();
|
||||
foreach (String key in dictionary.Keys)
|
||||
{
|
||||
ToolStripMenuItem m = new ToolStripMenuItem(dictionary[key].Item1);
|
||||
if (dictionary[key].Item2 != null)
|
||||
{
|
||||
m.Image = dictionary[key].Item2;
|
||||
}
|
||||
m.Click += ev;
|
||||
m.Name = key;
|
||||
m.Enabled = dictionary[key].Item3;
|
||||
if (dictionary[key].Item4)
|
||||
{
|
||||
m.Font = new System.Drawing.Font(m.Font, m.Font.Style | FontStyle.Bold);
|
||||
}
|
||||
l.Add(m);
|
||||
}
|
||||
return l.ToArray();
|
||||
}
|
||||
|
||||
private void showBallonTooltip(string text, ToolTipIcon toolTipIcon, string title = "NetMonitor Tray")
|
||||
{
|
||||
this.trayi.BalloonTipIcon = toolTipIcon;
|
||||
this.trayi.BalloonTipText = text;
|
||||
this.trayi.BalloonTipTitle = title;
|
||||
this.trayi.ShowBalloonTip(100);
|
||||
}
|
||||
|
||||
internal void Dispose()
|
||||
{
|
||||
this.trayi.Visible = false;
|
||||
Application.ExitThread();
|
||||
}
|
||||
|
||||
internal void setService(bool run)
|
||||
{
|
||||
this.showBallonTooltip((run ? "Service erfolgreich gestartet." : "Service erfolgreich beendet"), ToolTipIcon.Info);
|
||||
Model.Tray.Instance.setService(run);
|
||||
}
|
||||
|
||||
internal void showError(string text)
|
||||
{
|
||||
this.showBallonTooltip(text, ToolTipIcon.Error);
|
||||
}
|
||||
}
|
||||
}
|
BIN
NetMonitorTray/icon.ico
Normal file
After Width: | Height: | Size: 5.3 KiB |
BIN
NetMonitorTray/icon.png
Normal file
After Width: | Height: | Size: 795 B |
@ -0,0 +1,17 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace NetMonitorUtils.Execptions
|
||||
{
|
||||
[Serializable()]
|
||||
class ServiceControlArgumentException : System.Exception
|
||||
{
|
||||
public ServiceControlArgumentException() : base() { }
|
||||
public ServiceControlArgumentException(string message) : base(message) { }
|
||||
public ServiceControlArgumentException(string message, System.Exception inner) : base(message, inner) { }
|
||||
protected ServiceControlArgumentException(System.Runtime.Serialization.SerializationInfo info, System.Runtime.Serialization.StreamingContext context) { }
|
||||
}
|
||||
}
|
17
NetMonitorUtils/Execptions/ServiceControlException.cs
Normal file
@ -0,0 +1,17 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace NetMonitorUtils.Execptions
|
||||
{
|
||||
[Serializable()]
|
||||
class ServiceControlException : System.Exception
|
||||
{
|
||||
public ServiceControlException() : base() { }
|
||||
public ServiceControlException(string message) : base(message) { }
|
||||
public ServiceControlException(string message, System.Exception inner) : base(message, inner) { }
|
||||
protected ServiceControlException(System.Runtime.Serialization.SerializationInfo info, System.Runtime.Serialization.StreamingContext context) { }
|
||||
}
|
||||
}
|
17
NetMonitorUtils/Execptions/ServiceControlNetworkException.cs
Normal file
@ -0,0 +1,17 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace NetMonitorUtils.Execptions
|
||||
{
|
||||
[Serializable()]
|
||||
class ServiceControlNetworkException : System.Exception
|
||||
{
|
||||
public ServiceControlNetworkException() : base() { }
|
||||
public ServiceControlNetworkException(string message) : base(message) { }
|
||||
public ServiceControlNetworkException(string message, System.Exception inner) : base(message, inner) { }
|
||||
protected ServiceControlNetworkException(System.Runtime.Serialization.SerializationInfo info, System.Runtime.Serialization.StreamingContext context) { }
|
||||
}
|
||||
}
|
64
NetMonitorUtils/NetMonitorUtils.csproj
Normal file
@ -0,0 +1,64 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<Project ToolsVersion="4.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
|
||||
<PropertyGroup>
|
||||
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
|
||||
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
|
||||
<ProjectGuid>{45EE003D-5572-48FE-B90E-6BFE18D9EEC8}</ProjectGuid>
|
||||
<OutputType>Library</OutputType>
|
||||
<AppDesignerFolder>Properties</AppDesignerFolder>
|
||||
<RootNamespace>NetMonitorUtils</RootNamespace>
|
||||
<AssemblyName>NetMonitorUtils</AssemblyName>
|
||||
<TargetFrameworkVersion>v4.5</TargetFrameworkVersion>
|
||||
<FileAlignment>512</FileAlignment>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
|
||||
<DebugSymbols>true</DebugSymbols>
|
||||
<DebugType>full</DebugType>
|
||||
<Optimize>false</Optimize>
|
||||
<OutputPath>..\bin\Debug\</OutputPath>
|
||||
<DefineConstants>DEBUG;TRACE</DefineConstants>
|
||||
<ErrorReport>prompt</ErrorReport>
|
||||
<WarningLevel>4</WarningLevel>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
|
||||
<DebugType>pdbonly</DebugType>
|
||||
<Optimize>true</Optimize>
|
||||
<OutputPath>..\bin\Release\</OutputPath>
|
||||
<DefineConstants>TRACE</DefineConstants>
|
||||
<ErrorReport>prompt</ErrorReport>
|
||||
<WarningLevel>4</WarningLevel>
|
||||
</PropertyGroup>
|
||||
<ItemGroup>
|
||||
<Reference Include="System" />
|
||||
<Reference Include="System.Core" />
|
||||
<Reference Include="System.ServiceProcess" />
|
||||
<Reference Include="System.Xml.Linq" />
|
||||
<Reference Include="System.Data.DataSetExtensions" />
|
||||
<Reference Include="Microsoft.CSharp" />
|
||||
<Reference Include="System.Data" />
|
||||
<Reference Include="System.Xml" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Compile Include="Execptions\ServiceControlNetworkException.cs" />
|
||||
<Compile Include="Execptions\ServiceControlArgumentException.cs" />
|
||||
<Compile Include="Execptions\ServiceControlException.cs" />
|
||||
<Compile Include="NetworkSetter.cs" />
|
||||
<Compile Include="Properties\AssemblyInfo.cs" />
|
||||
<Compile Include="ServiceControl.cs" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\..\Utils\Utils\Utils.csproj">
|
||||
<Project>{fac8ce64-bf13-4ece-8097-aeb5dd060098}</Project>
|
||||
<Name>Utils</Name>
|
||||
</ProjectReference>
|
||||
</ItemGroup>
|
||||
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
|
||||
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
|
||||
Other similar extension points exist, see Microsoft.Common.targets.
|
||||
<Target Name="BeforeBuild">
|
||||
</Target>
|
||||
<Target Name="AfterBuild">
|
||||
</Target>
|
||||
-->
|
||||
</Project>
|
182
NetMonitorUtils/NetworkSetter.cs
Normal file
@ -0,0 +1,182 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using BlubbFish.Utils;
|
||||
|
||||
namespace NetMonitorUtils
|
||||
{
|
||||
public class NetworkSetter : OwnObject
|
||||
{
|
||||
private ServiceControl serviceController;
|
||||
private InIReader networkini;
|
||||
|
||||
private enum netsetterType
|
||||
{
|
||||
Auto,
|
||||
IpAuto,
|
||||
Ip,
|
||||
DnsAuto,
|
||||
Dns,
|
||||
WinsAuto,
|
||||
Wins
|
||||
}
|
||||
public NetworkSetter(string networkfile, string configfile)
|
||||
{
|
||||
this.addLog("NetworkSetter", "networkfile: " + networkfile + "; configfile: " + configfile + ";", LogLevel.Debug);
|
||||
this.serviceController = ServiceControl.getInstance(configfile);
|
||||
this.networkini = InIReader.getInstance(networkfile);
|
||||
}
|
||||
public bool setNetwork(string networkName)
|
||||
{
|
||||
this.addLog("setNetwork", "Setze Netzwerkeinstellungen: " + networkName, LogLevel.Info);
|
||||
this.addLog("setNetwork", "networkName: " + networkName + ";", LogLevel.Debug);
|
||||
String name = networkini.getValue(networkName, "Name");
|
||||
String ip = networkini.getValue(networkName, "Ip");
|
||||
String subnet = networkini.getValue(networkName, "Subnet");
|
||||
String gateway = networkini.getValue(networkName, "Gateway");
|
||||
String dns = networkini.getValue(networkName, "Dns");
|
||||
String wins = networkini.getValue(networkName, "Wins");
|
||||
String adapter = networkini.getValue(networkName, "Adapter");
|
||||
this.addLog("setNetwork", "name: " + name, LogLevel.Debug);
|
||||
this.addLog("setNetwork", "ip: " + ip, LogLevel.Debug);
|
||||
this.addLog("setNetwork", "subnet: " + subnet, LogLevel.Debug);
|
||||
this.addLog("setNetwork", "gateway: " + gateway, LogLevel.Debug);
|
||||
this.addLog("setNetwork", "dns: " + dns, LogLevel.Debug);
|
||||
this.addLog("setNetwork", "wins: " + wins, LogLevel.Debug);
|
||||
this.addLog("setNetwork", "adapter: " + adapter, LogLevel.Debug);
|
||||
bool ret = false;
|
||||
if (ip.ToLower() == "auto" && dns.ToLower() == "auto" && wins.ToLower() == "auto")
|
||||
{
|
||||
ret = setNetworkAuto(adapter, name);
|
||||
this.addLog("setNetwork.setNetworkAuto", "return " + ret, LogLevel.Debug);
|
||||
}
|
||||
else
|
||||
{
|
||||
if (ip.ToLower() == "auto")
|
||||
{
|
||||
ret = setNetworkIpAuto(adapter, name);
|
||||
this.addLog("setNetwork.setNetworkIpAuto", "return " + ret, LogLevel.Debug);
|
||||
}
|
||||
else
|
||||
{
|
||||
ret = setNetworkIp(ip, subnet, gateway, adapter, name);
|
||||
this.addLog("setNetwork.setNetworkIp", "return " + ret, LogLevel.Debug);
|
||||
}
|
||||
if (dns.ToLower() == "auto")
|
||||
{
|
||||
ret = setNetworkDnsAuto(adapter, name);
|
||||
this.addLog("setNetwork.setNetworkDnsAuto", "return " + ret, LogLevel.Debug);
|
||||
}
|
||||
else
|
||||
{
|
||||
ret = setNetworkDns(dns, adapter, name);
|
||||
this.addLog("setNetwork.setNetworkDns", "return " + ret, LogLevel.Debug);
|
||||
}
|
||||
if (wins.ToLower() == "auto")
|
||||
{
|
||||
ret = setNetworkWinsAuto(adapter, name);
|
||||
this.addLog("setNetwork.setNetworkWinsAuto", "return " + ret, LogLevel.Debug);
|
||||
}
|
||||
else
|
||||
{
|
||||
ret = setNetworkWins(wins, adapter, name);
|
||||
this.addLog("setNetwork.setNetworkWins", "return " + ret, LogLevel.Debug);
|
||||
}
|
||||
}
|
||||
this.addLog("setNetwork", "return " + ret, LogLevel.Debug);
|
||||
return ret;
|
||||
}
|
||||
public bool setNetworkAuto(string adapter, string name)
|
||||
{
|
||||
this.addLog("setNetworkAuto", "Setze Netzwerkeinstellungen von " + adapter + " auf Automatisch", LogLevel.Info);
|
||||
this.addLog("setNetworkAuto", "datapter: " + adapter + "; name: " + name + ";", LogLevel.Debug);
|
||||
return setNetwork(netsetterType.Auto, null, null, null, adapter, name, null, null);
|
||||
}
|
||||
public bool setNetworkIpAuto(string adapter, string name)
|
||||
{
|
||||
this.addLog("setNetworkIpAuto", "Setze Netzwerkeinstellungen von " + adapter + " auf IP Automatisch", LogLevel.Info);
|
||||
this.addLog("setNetworkIpAuto", "adapter: " + adapter + "; name: " + name + ";", LogLevel.Debug);
|
||||
return setNetwork(netsetterType.IpAuto, null, null, null, adapter, name, null, null);
|
||||
}
|
||||
public bool setNetworkIp(string ip, string subnet, string gateway, string adapter, string name)
|
||||
{
|
||||
this.addLog("setNetworkIp", "Setze Netzwerkeinstellungen von " + adapter + " auf IP " + ip + "/" + subnet + " GW " + gateway, LogLevel.Info);
|
||||
this.addLog("setNetworkIp", "ip: " + ip + "; subnet: " + subnet + "; gateway: " + gateway + "; adapter: " + adapter + "; name: " + name + ";", LogLevel.Debug);
|
||||
return setNetwork(netsetterType.Ip, ip, subnet, gateway, adapter, name, null, null);
|
||||
}
|
||||
public bool setNetworkDnsAuto(string adapter, string name)
|
||||
{
|
||||
this.addLog("setNetworkDnsAuto", "Setze Netzwerkeinstellungen von " + adapter + " auf Dns Automatisch", LogLevel.Info);
|
||||
this.addLog("setNetworkDnsAuto", "adapter: " + adapter + "; name: " + name + ";", LogLevel.Debug);
|
||||
return setNetwork(netsetterType.DnsAuto, null, null, null, adapter, name, null, null);
|
||||
}
|
||||
public bool setNetworkDns(string dns, string adapter, string name)
|
||||
{
|
||||
this.addLog("setNetworkDns", "Setze Netzwerkeinstellungen von " + adapter + " auf Dns " + dns, LogLevel.Info);
|
||||
this.addLog("setNetworkDns", "dns: " + dns + "; adapter: " + adapter + "; name: " + name + ";", LogLevel.Debug);
|
||||
return setNetwork(netsetterType.Dns, null, null, null, adapter, name, dns, null);
|
||||
}
|
||||
public bool setNetworkWinsAuto(string adapter, string name)
|
||||
{
|
||||
this.addLog("setNetworkWinsAuto", "Setze Netzwerkeinstellungen von " + adapter + " auf Wins Automatisch", LogLevel.Info);
|
||||
this.addLog("setNetworkWinsAuto", "adapter: " + adapter + "; name: " + name + ";", LogLevel.Debug);
|
||||
return setNetwork(netsetterType.WinsAuto, null, null, null, adapter, name, null, null);
|
||||
}
|
||||
public bool setNetworkWins(string wins, string adapter, string name)
|
||||
{
|
||||
this.addLog("setNetworkWins", "Setze Netzwerkeinstellungen von " + adapter + " auf Wins " + wins, LogLevel.Info);
|
||||
this.addLog("setNetworkWins", "wins: " + wins + "; adapter: " + adapter + "; name: " + name + ";", LogLevel.Debug);
|
||||
return setNetwork(netsetterType.Wins, null, null, null, adapter, name, null, wins);
|
||||
}
|
||||
private bool setNetwork(netsetterType option, string ip, string subnet, string gateway, string adapter, string name, string dns, string wins)
|
||||
{
|
||||
this.addLog("setNetwork", "option: " + option + "; ip: " + ip + "; subnet: " + subnet + "; gateway: " + gateway + "; adapter: " + adapter + "; name: " + name + "; dns: " + dns + "; wins: " + wins + ";", LogLevel.Debug);
|
||||
bool status = false;
|
||||
try
|
||||
{
|
||||
if (option == netsetterType.Ip)
|
||||
{
|
||||
this.addLog("ServiceController.NetworkSetIp", "ip: "+ip+"; subnet: "+subnet+"; gateway: "+gateway+"; adapter: "+adapter+";", LogLevel.Debug);
|
||||
status = this.serviceController.NetworkSetIp(ip, subnet, gateway, adapter);
|
||||
}
|
||||
if (option == netsetterType.Auto)
|
||||
{
|
||||
this.addLog("ServiceController.NetworkSetAuto", "adapter: "+adapter+";", LogLevel.Debug);
|
||||
status = this.serviceController.NetworkSetAuto(adapter);
|
||||
}
|
||||
if (option == netsetterType.IpAuto)
|
||||
{
|
||||
this.addLog("ServiceController.NetworkSetIpAuto", "adapter: "+adapter+";", LogLevel.Debug);
|
||||
status = this.serviceController.NetworkSetIpAuto(adapter);
|
||||
}
|
||||
if (option == netsetterType.DnsAuto)
|
||||
{
|
||||
this.addLog("ServiceController.NetworkSetDnsAuto", "adapter: "+adapter+";", LogLevel.Debug);
|
||||
status = this.serviceController.NetworkSetDnsAuto(adapter);
|
||||
}
|
||||
if (option == netsetterType.WinsAuto)
|
||||
{
|
||||
this.addLog("ServiceController.NetworkSetWinsAuto", "adapter: "+adapter+";", LogLevel.Debug);
|
||||
status = this.serviceController.NetworkSetWinsAuto(adapter);
|
||||
}
|
||||
if (option == netsetterType.Dns)
|
||||
{
|
||||
this.addLog("ServiceController.NetworkSetDNS", "dns: "+dns+"; adapter: "+adapter+";", LogLevel.Debug);
|
||||
status = this.serviceController.NetworkSetDNS(dns, adapter);
|
||||
}
|
||||
if (option == netsetterType.Wins)
|
||||
{
|
||||
this.addLog("ServiceController.NetworkSetWINS", "wins: "+wins+"; adapter: "+adapter+";", LogLevel.Debug);
|
||||
status = this.serviceController.NetworkSetWINS(wins, adapter);
|
||||
}
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
this.addLog("setNetwork", "Fehler beim Ausführen des Befehls: " + e.Message, LogLevel.Error);
|
||||
throw e;
|
||||
}
|
||||
return status;
|
||||
}
|
||||
}
|
||||
}
|
36
NetMonitorUtils/Properties/AssemblyInfo.cs
Normal file
@ -0,0 +1,36 @@
|
||||
using System.Reflection;
|
||||
using System.Runtime.CompilerServices;
|
||||
using System.Runtime.InteropServices;
|
||||
|
||||
// Allgemeine Informationen über eine Assembly werden über die folgenden
|
||||
// Attribute gesteuert. Ändern Sie diese Attributwerte, um die Informationen zu ändern,
|
||||
// die mit einer Assembly verknüpft sind.
|
||||
[assembly: AssemblyTitle("NetMonitorUtils")]
|
||||
[assembly: AssemblyDescription("")]
|
||||
[assembly: AssemblyConfiguration("")]
|
||||
[assembly: AssemblyCompany("")]
|
||||
[assembly: AssemblyProduct("NetMonitorUtils")]
|
||||
[assembly: AssemblyCopyright("Copyright © 2014")]
|
||||
[assembly: AssemblyTrademark("")]
|
||||
[assembly: AssemblyCulture("")]
|
||||
|
||||
// Durch Festlegen von ComVisible auf "false" werden die Typen in dieser Assembly unsichtbar
|
||||
// für COM-Komponenten. Wenn Sie auf einen Typ in dieser Assembly von
|
||||
// COM zugreifen müssen, legen Sie das ComVisible-Attribut für diesen Typ auf "true" fest.
|
||||
[assembly: ComVisible(false)]
|
||||
|
||||
// Die folgende GUID bestimmt die ID der Typbibliothek, wenn dieses Projekt für COM verfügbar gemacht wird
|
||||
[assembly: Guid("2c86a911-78de-4ced-a0fe-d63cd945c0ae")]
|
||||
|
||||
// Versionsinformationen für eine Assembly bestehen aus den folgenden vier Werten:
|
||||
//
|
||||
// Hauptversion
|
||||
// Nebenversion
|
||||
// Buildnummer
|
||||
// Revision
|
||||
//
|
||||
// Sie können alle Werte angeben oder die standardmäßigen Build- und Revisionsnummern
|
||||
// übernehmen, indem Sie "*" eingeben:
|
||||
// [assembly: AssemblyVersion("1.0.*")]
|
||||
[assembly: AssemblyVersion("1.0.0.0")]
|
||||
[assembly: AssemblyFileVersion("1.0.0.0")]
|
227
NetMonitorUtils/ServiceControl.cs
Normal file
@ -0,0 +1,227 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.ServiceProcess;
|
||||
using System.Net.Sockets;
|
||||
using System.Net;
|
||||
using BlubbFish.Utils;
|
||||
using NetMonitorUtils.Execptions;
|
||||
|
||||
namespace NetMonitorUtils
|
||||
{
|
||||
public class ServiceControl
|
||||
{
|
||||
private ServiceController sc = new ServiceController();
|
||||
private static ServiceControl instance;
|
||||
private InIReader config;
|
||||
private ServiceControl(string configfile)
|
||||
{
|
||||
this.sc.ServiceName = "NetMonitorServer";
|
||||
this.config = InIReader.getInstance(configfile);
|
||||
}
|
||||
|
||||
public static ServiceControl getInstance(string configfile)
|
||||
{
|
||||
if (instance == null)
|
||||
{
|
||||
instance = new ServiceControl(configfile);
|
||||
}
|
||||
return instance;
|
||||
}
|
||||
|
||||
private bool ServiceSetStatus(ServiceControllerStatus status)
|
||||
{
|
||||
if (this.sc.Status == status)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
this.sc.Start();
|
||||
try
|
||||
{
|
||||
this.sc.WaitForStatus(status, new TimeSpan(0, 0, 30));
|
||||
}
|
||||
catch (System.ServiceProcess.TimeoutException)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public bool ServiceStart()
|
||||
{
|
||||
return this.ServiceSetStatus(ServiceControllerStatus.Running);
|
||||
}
|
||||
|
||||
public bool ServicePause()
|
||||
{
|
||||
return this.ServiceSetStatus(ServiceControllerStatus.Paused);
|
||||
}
|
||||
|
||||
public bool ServiceStop()
|
||||
{
|
||||
return this.ServiceSetStatus(ServiceControllerStatus.Stopped);
|
||||
}
|
||||
|
||||
public bool NetworkSetAuto(string adapter)
|
||||
{
|
||||
if (adapter == null)
|
||||
{
|
||||
throw new ServiceControlArgumentException("Adapter ist not Set!");
|
||||
}
|
||||
return this.sendMessage("NET","AUTO "+adapter);
|
||||
}
|
||||
|
||||
private bool sendMessage(string method, string message)
|
||||
{
|
||||
IPEndPoint netRecieverPoint = new IPEndPoint(IPAddress.Loopback, 0);
|
||||
int startPort = Int32.Parse(this.config.getValue("ports", "client_from"));
|
||||
int rangePort = Int32.Parse(this.config.getValue("ports", "client_to"));
|
||||
UdpClient netReciver = null;
|
||||
int selectedPort = 0;
|
||||
for (int i = startPort; i < rangePort; i++)
|
||||
{
|
||||
try
|
||||
{
|
||||
netReciver = new UdpClient(i);
|
||||
}
|
||||
catch (System.Net.Sockets.SocketException) { }
|
||||
if (netReciver != null)
|
||||
{
|
||||
selectedPort = i;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (netReciver == null)
|
||||
{
|
||||
throw new ServiceControlException("No Free Port for Comunication");
|
||||
}
|
||||
byte[] data = Encoding.UTF8.GetBytes(method + " " + selectedPort + " " + message);
|
||||
|
||||
UdpClient netSender = new UdpClient();
|
||||
IPEndPoint netSenderPoint = new IPEndPoint(IPAddress.Loopback, Int32.Parse(this.config.getValue("ports", "server")));
|
||||
netSender.Send(data, data.Length, netSenderPoint);
|
||||
netReciver.Client.ReceiveTimeout = 60000;
|
||||
byte[] recivedData;
|
||||
try
|
||||
{
|
||||
recivedData = netReciver.Receive(ref netRecieverPoint);
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
throw new ServiceControlNetworkException(e.Message);
|
||||
}
|
||||
string recieveText = Encoding.UTF8.GetString(recivedData);
|
||||
if (recieveText.ToLower() == "true")
|
||||
{
|
||||
return true;
|
||||
}
|
||||
else
|
||||
{
|
||||
throw new ServiceControlException(recieveText);
|
||||
}
|
||||
}
|
||||
|
||||
public bool NetworkSetIp(string ip, string subnet, string gateway, string adapter)
|
||||
{
|
||||
if (ip == null)
|
||||
{
|
||||
throw new ServiceControlArgumentException("IP address not Set!");
|
||||
}
|
||||
if (subnet == null)
|
||||
{
|
||||
throw new ServiceControlArgumentException("Subnet address not Set!");
|
||||
}
|
||||
if (gateway == null)
|
||||
{
|
||||
throw new ServiceControlArgumentException("Gateway address not Set!");
|
||||
}
|
||||
if (adapter == null)
|
||||
{
|
||||
throw new ServiceControlArgumentException("Adapter ist not Set!");
|
||||
}
|
||||
return this.sendMessage("NET", "IP " + ip + " " + subnet + " " + gateway + " " + adapter);
|
||||
}
|
||||
|
||||
public bool NetworkSetDNS(string dns, string adapter)
|
||||
{
|
||||
if (dns == null)
|
||||
{
|
||||
throw new ServiceControlArgumentException("DNS address not Set!");
|
||||
}
|
||||
if (adapter == null)
|
||||
{
|
||||
throw new ServiceControlArgumentException("Adapter ist not Set!");
|
||||
}
|
||||
return this.sendMessage("NET", "DNS " + dns + " " + adapter);
|
||||
}
|
||||
|
||||
public bool NetworkSetWINS(string wins, string adapter)
|
||||
{
|
||||
if (wins == null)
|
||||
{
|
||||
throw new ServiceControlArgumentException("WINS address not Set!");
|
||||
}
|
||||
if (adapter == null)
|
||||
{
|
||||
throw new ServiceControlArgumentException("Adapter ist not Set!");
|
||||
}
|
||||
return this.sendMessage("NET", "WINS " + wins + " " + adapter);
|
||||
}
|
||||
|
||||
public bool NetworkSetIpAuto(string adapter)
|
||||
{
|
||||
if (adapter == null)
|
||||
{
|
||||
throw new ServiceControlArgumentException("Adapter ist not Set!");
|
||||
}
|
||||
return this.sendMessage("NET", "IP AUTO "+adapter);
|
||||
}
|
||||
|
||||
|
||||
public bool NetworkSetDnsAuto(string adapter)
|
||||
{
|
||||
if (adapter == null)
|
||||
{
|
||||
throw new ServiceControlArgumentException("Adapter ist not Set!");
|
||||
}
|
||||
return this.sendMessage("NET", "DNS AUTO " + adapter);
|
||||
}
|
||||
|
||||
public bool NetworkSetWinsAuto(string adapter)
|
||||
{
|
||||
if (adapter == null)
|
||||
{
|
||||
throw new ServiceControlArgumentException("Adapter ist not Set!");
|
||||
}
|
||||
return this.sendMessage("NET", "WINS AUTO " + adapter);
|
||||
}
|
||||
|
||||
public bool ServiceStart(string name)
|
||||
{
|
||||
if (name == null)
|
||||
{
|
||||
throw new ServiceControlArgumentException("Service name ist not set!");
|
||||
}
|
||||
return this.sendMessage("SERVICE", "START " + name);
|
||||
}
|
||||
|
||||
public bool ServiceStop(string name)
|
||||
{
|
||||
if (name == null)
|
||||
{
|
||||
throw new ServiceControlArgumentException("Service name ist not set!");
|
||||
}
|
||||
return this.sendMessage("SERVICE", "STOP " + name);
|
||||
}
|
||||
|
||||
public bool ServiceStatus(string name)
|
||||
{
|
||||
if (name == null)
|
||||
{
|
||||
throw new ServiceControlArgumentException("Service name ist not set!");
|
||||
}
|
||||
return this.sendMessage("SERVICE", "STATUS " + name);
|
||||
}
|
||||
}
|
||||
}
|
BIN
NetOpenVPNGUI/Resources/icon_con.ico
Normal file
After Width: | Height: | Size: 5.3 KiB |
BIN
bin/Debug/NetMonitorConsole.exe
Normal file
BIN
bin/Debug/NetMonitorServer.exe
Normal file
BIN
bin/Debug/NetMonitorTray.exe
Normal file
BIN
bin/Debug/NetMonitorUtils.dll
Normal file
BIN
bin/Debug/Utils.dll
Normal file
4
bin/Debug/config.ini
Normal file
@ -0,0 +1,4 @@
|
||||
[ports]
|
||||
server=54323
|
||||
client_from=54330
|
||||
client_to=54340
|
6
bin/Debug/network.ini
Normal file
@ -0,0 +1,6 @@
|
||||
[network1]
|
||||
Name=Home
|
||||
Ip=auto
|
||||
Dns=auto
|
||||
Wins=auto
|
||||
Adapter=LAN-Verbindung
|