Skip to content

Commit

Permalink
Protocol:
Browse files Browse the repository at this point in the history
Add IPv6 address usage
Tray List windows:
Add winbox to List context menu
Context menu point new error message, when process not found
Add IPv6 column
Common:
Set startup object path to public (Program.cs, Program class, Program.Main method)
  • Loading branch information
xmegz committed Mar 15, 2019
1 parent 65093a6 commit d965c8c
Show file tree
Hide file tree
Showing 18 changed files with 184 additions and 119 deletions.
6 changes: 3 additions & 3 deletions MndpTray/MndpService/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@

namespace MndpService
{
internal static class Program
public static class Program
{
private static void Main(string[] args)
public static void Main(string[] args)
{
AppDomain.CurrentDomain.UnhandledException += CurrentDomain_UnhandledException;

Expand All @@ -30,7 +30,7 @@ private static void Main(string[] args)

private static readonly object LOG_FILE_LOCK = new object();
private static readonly string LOG_FILE_NAME = GetLogFileName("log");
private static readonly bool LOG_FILE_IS_ENABLED = File.Exists(LOG_FILE_NAME);
private static readonly bool LOG_FILE_IS_ENABLED = File.Exists(GetLogFileName("log"));

#endregion Fields

Expand Down
4 changes: 2 additions & 2 deletions MndpTray/MndpService/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,5 +32,5 @@
// 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.5.3.0")]
[assembly: AssemblyFileVersion("1.5.3.0")]
[assembly: AssemblyVersion("1.6.0.0")]
[assembly: AssemblyFileVersion("1.6.0.0")]
44 changes: 21 additions & 23 deletions MndpTray/MndpTray.Protocol.Test/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,31 +3,29 @@

namespace MndpTray.Protocol.Test
{

internal class Program
{
private static readonly Timer Timer = new Timer(Timer_Callback, null, Timeout.Infinite, Timeout.Infinite);
public class Program
{
private static readonly Timer Timer = new Timer(Timer_Callback, null, Timeout.Infinite, Timeout.Infinite);

private static void Timer_Callback(object state)
{
foreach (var i in MndpListener.Instance.GetMessages()) Console.WriteLine(i.Value.ToString());
Console.WriteLine("--- Message List End ---");
}
public static void Main(string[] args)
{
MndpListener.Instance.Start();
MndpSender.Instance.Start(MndpHostInfo.Instance);
Timer.Change(0, 5000);

private static void Main(string[] args)
{
MndpListener.Instance.Start();
MndpSender.Instance.Start(MndpHostInfo.Instance);
Timer.Change(0, 5000);
Console.WriteLine("--- Start ---");
while (!Console.KeyAvailable) { Thread.Sleep(100); }
Console.WriteLine("--- Stop ---");

Console.WriteLine("--- Start ---");
while (!Console.KeyAvailable) { Thread.Sleep(100); }
Console.WriteLine("--- Stop ---");
Timer.Change(Timeout.Infinite, Timeout.Infinite);
MndpListener.Instance.Stop();
MndpSender.Instance.Stop();
}

Timer.Change(Timeout.Infinite, Timeout.Infinite);
MndpListener.Instance.Stop();
MndpSender.Instance.Stop();
}
private static void Timer_Callback(object state)
{
foreach (var i in MndpListener.Instance.GetMessages()) Console.WriteLine(i.Value.ToString());
Console.WriteLine("--- Message List End ---");
}

}
}
}
6 changes: 3 additions & 3 deletions MndpTray/MndpTray.Protocol.Test/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
[assembly: AssemblyTitle("MndpTray.Protocol.Test")]
[assembly: AssemblyDescription("MndpTray.Protocol Package Test Application")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyCompany("Pádár Tamás")]
[assembly: AssemblyProduct("MndpTray.Protocol.Test")]
[assembly: AssemblyCopyright("Copyright © 2019")]
[assembly: AssemblyTrademark("")]
Expand All @@ -32,5 +32,5 @@
// 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.5.3.0")]
[assembly: AssemblyFileVersion("1.5.3.0")]
[assembly: AssemblyVersion("1.6.0.0")]
[assembly: AssemblyFileVersion("1.6.0.0")]
2 changes: 1 addition & 1 deletion MndpTray/MndpTray.Protocol.Test/packages.config
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="MndpTray.Protocol" version="1.5.0" targetFramework="net461" />
<package id="MndpTray.Protocol" version="1.5.0" targetFramework="net452" />
</packages>
6 changes: 6 additions & 0 deletions MndpTray/MndpTray.Protocol/IMndpInterfaceInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,5 +27,11 @@ public interface IMndpInterfaceInfo
/// </summary>
/// <example>192.168.0.1</example>
string UnicastAddress { get; }

/// <summary>
/// Interface Ipv6 unicast address
/// </summary>
/// <example>fe80::2d1f:d9f4:4c05:a200</example>
string UnicastIPv6Address { get; }
}
}
9 changes: 7 additions & 2 deletions MndpTray/MndpTray.Protocol/MndpHostInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -71,18 +71,23 @@ public List<IMndpInterfaceInfo> InterfaceInfos
.ToList();

foreach (var @interface in interfaces)
foreach (var unicastAddress in @interface.GetIPProperties().UnicastAddresses)
{
var addresses = @interface.GetIPProperties().UnicastAddresses;
foreach (var unicastAddress in addresses)
{
if (unicastAddress.Address.AddressFamily == System.Net.Sockets.AddressFamily.InterNetwork && unicastAddress.IPv4Mask != null)
{
var addressInt = BitConverter.ToInt32(unicastAddress.Address.GetAddressBytes(), 0);
var maskInt = BitConverter.ToInt32(unicastAddress.IPv4Mask.GetAddressBytes(), 0);
var broadcastInt = addressInt | ~maskInt;
var broadcast = new IPAddress(BitConverter.GetBytes(broadcastInt));
var ipv6Address = addresses.Where(a => a.Address.AddressFamily == System.Net.Sockets.AddressFamily.InterNetworkV6).FirstOrDefault()?.Address;


ret.Add(new MndpInterfaceInfo(broadcast.ToString(), @interface.Name, @interface.GetPhysicalAddress().ToString(), unicastAddress.Address.ToString()));
ret.Add(new MndpInterfaceInfo(broadcast.ToString(), @interface.Name, @interface.GetPhysicalAddress().ToString(), unicastAddress.Address.ToString(), ipv6Address?.ToString()));
}
}
}
}
catch (Exception ex)
{
Expand Down
10 changes: 9 additions & 1 deletion MndpTray/MndpTray.Protocol/MndpInterfaceInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,12 @@ public class MndpInterfaceInfo : IMndpInterfaceInfo
/// <example>192.168.0.1</example>
public String UnicastAddress { get; }

/// <summary>
/// Interface Ipv6 unicast address
/// </summary>
/// <example>fe80::2d1f:d9f4:4c05:a200</example>
public String UnicastIPv6Address { get; }

#endregion Props

#region Methods
Expand All @@ -43,12 +49,14 @@ public class MndpInterfaceInfo : IMndpInterfaceInfo
/// <param name="interfaceName">Interface name</param>
/// <param name="macAddress">Interface mac address 12 hexdigit</param>
/// <param name="unicastAddress">Interface unicast address</param>
public MndpInterfaceInfo(string broadcastAddress, string interfaceName, string macAddress, string unicastAddress)
/// <param name="unicastIpv6Address">Interface Ipv6 unicast address</param>
public MndpInterfaceInfo(string broadcastAddress, string interfaceName, string macAddress, string unicastAddress, string unicastIpv6Address)
{
this.BroadcastAddress = broadcastAddress;
this.InterfaceName = interfaceName;
this.MacAddress = macAddress;
this.UnicastAddress = unicastAddress;
this.UnicastIPv6Address = unicastIpv6Address;
}

#endregion Methods
Expand Down
42 changes: 31 additions & 11 deletions MndpTray/MndpTray.Protocol/MndpMessage.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Net;
using System.Net.NetworkInformation;
using System.Text;

Expand All @@ -16,6 +17,7 @@ public class MndpMessage
private const ushort TLV_TYPE_BOARD_NAME = 12;
private const ushort TLV_TYPE_IDENTITY = 5;
private const ushort TLV_TYPE_INTERFACE_NAME = 16;
private const ushort TLV_TYPE_IPV6 = 15;
private const ushort TLV_TYPE_MAC_ADDRESS = 1;
private const ushort TLV_TYPE_PLATFORM = 8;
private const ushort TLV_TYPE_SOFTWAREID = 11;
Expand All @@ -26,6 +28,7 @@ public class MndpMessage
#endregion Consts

#region Props

/// <summary>
/// Sender board name
/// </summary>
Expand All @@ -41,6 +44,11 @@ public class MndpMessage
/// </summary>
public string InterfaceName { get; set; }

/// <summary>
/// Sender unicast IPv6 address
/// </summary>
public string UnicastIPv6Address { get; set; }

/// <summary>
/// Sender mac address
/// </summary>
Expand Down Expand Up @@ -82,7 +90,7 @@ public class MndpMessage
public TimeSpan Uptime { get; set; }

/// <summary>
/// Sender software version
/// Sender software version
/// </summary>
public string Version { get; set; }

Expand Down Expand Up @@ -150,11 +158,15 @@ public bool Read(byte[] data)
this.InterfaceName = enc.GetString(i.Value);
break;

case TLV_TYPE_IPV6:
this.UnicastIPv6Address = new IPAddress(i.Value).ToString();
break;

default: break;
}
}

Log.Info("{0} Read,{2}{1}{2}",nameof(MndpMessage), this.ToString(), Environment.NewLine);
Log.Info("{0} Read,{2}{1}{2}", nameof(MndpMessage), this.ToString(), Environment.NewLine);

return true;
}
Expand Down Expand Up @@ -186,6 +198,7 @@ public override string ToString()
sb.AppendFormat("\t{0}:{1}," + Environment.NewLine, nameof(this.BoardName), this.BoardName);
sb.AppendFormat("\t{0}:{1}," + Environment.NewLine, nameof(this.Unpack), this.Unpack);
sb.AppendFormat("\t{0}:{1}," + Environment.NewLine, nameof(this.InterfaceName), this.InterfaceName);
sb.AppendFormat("\t{0}:{1}," + Environment.NewLine, nameof(this.UnicastIPv6Address), this.UnicastIPv6Address);

return sb.ToString();
}
Expand All @@ -198,7 +211,7 @@ public byte[] Write()
{
try
{
Log.Info("{0} Write,{2}{1}{2}", nameof(MndpMessage), this.ToString(),Environment.NewLine);
Log.Info("{0} Write,{2}{1}{2}", nameof(MndpMessage), this.ToString(), Environment.NewLine);

var tlvMessage = new TlvMessage()
{
Expand Down Expand Up @@ -249,6 +262,11 @@ public byte[] Write()
tlvMessage.Items.Add(new Tlv(i, this.InterfaceName, enc));
break;

case TLV_TYPE_IPV6:
if (this.UnicastIPv6Address != null)
tlvMessage.Items.Add(new Tlv(i, IPAddress.Parse(this.UnicastIPv6Address).GetAddressBytes()));
break;

default: break;
}
}
Expand Down Expand Up @@ -285,7 +303,7 @@ protected class Tlv
/// Record length
/// </summary>
public ushort Length { get; set; }

/// <summary>
/// Record vlue
/// </summary>
Expand Down Expand Up @@ -589,7 +607,7 @@ public class MndpMessageEx : MndpMessage, ICloneable
public DateTime ReceiveDateTime { get; set; }

/// <summary>
/// Sender unicast IPv4 address
/// Sender unicast IPv4 address
/// </summary>
public string UnicastAddress { get; set; }

Expand All @@ -599,22 +617,24 @@ public class MndpMessageEx : MndpMessage, ICloneable
/// <example>
/// AA:BB:CC:DD:EE:FF
/// </example>
public string MacAddressDelimited {
public string MacAddressDelimited
{
get
{
if (this.MacAddress == null) return null;
StringBuilder sb = new StringBuilder();
for(int i=0;i<this.MacAddress.Length;i++)

for (int i = 0; i < this.MacAddress.Length; i++)
{
sb.Append(this.MacAddress[i]);
if (i % 2 == 1) sb.Append(':');
}

if (sb.Length > 0) sb.Remove(sb.Length - 1, 1);
return sb.ToString();
}
}

} }
#endregion Props

#region Methods
Expand All @@ -637,8 +657,8 @@ public override string ToString()
var sb = new StringBuilder();

sb.AppendFormat("\t{0}:{1}," + Environment.NewLine, nameof(this.ReceiveDateTime), this.ReceiveDateTime);
sb.AppendFormat("\t{0}:{1}," + Environment.NewLine, nameof(this.UnicastAddress), this.UnicastAddress);
sb.AppendFormat("\t{0}:{1}," + Environment.NewLine, nameof(this.BroadcastAddress),this.BroadcastAddress);
sb.AppendFormat("\t{0}:{1}," + Environment.NewLine, nameof(this.UnicastAddress), this.UnicastAddress);
sb.AppendFormat("\t{0}:{1}," + Environment.NewLine, nameof(this.BroadcastAddress), this.BroadcastAddress);
sb.Append(base.ToString());

return sb.ToString();
Expand Down
1 change: 1 addition & 0 deletions MndpTray/MndpTray.Protocol/MndpSender.cs
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,7 @@ private void _sendHostInfoWork()
msg.InterfaceName = i.InterfaceName;
msg.MacAddress = i.MacAddress;
msg.UnicastAddress = i.UnicastAddress;
msg.UnicastIPv6Address = i.UnicastIPv6Address;

this.Send((MndpMessageEx)msg.Clone());
}
Expand Down
Binary file modified MndpTray/MndpTray.Protocol/Properties/AssemblyInfo.cs
Binary file not shown.
4 changes: 2 additions & 2 deletions MndpTray/MndpTray.Protocol/package.nuspec
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,12 @@
<iconUrl>https://raw.githubusercontent.com/xmegz/MndpTray/master/MndpTray/MndpTray/Images/favicon.ico</iconUrl>
<requireLicenseAcceptance>false</requireLicenseAcceptance>
<!--*-->
<description>Mikrotik Neighbor Discovery Protocol</description>
<description>Mikrotik Neighbor Discovery Protocol - Network Discovery</description>
<!--*-->
<repository type="git" url="https://github.com/xmegz/MndpTray" />
<releaseNotes>IMndpHostInfo InterfaceInfo also interface</releaseNotes>
<copyright>Copyright © 2018</copyright>
<tags>Mikrotik Discovery Protocol</tags>
<tags>Mikrotik Discovery Protocol Network Udp Broadcast Windows Routeros Mndp</tags>
<dependencies>
<!--
<dependency id="SampleDependency" version="1.0" />
Expand Down
9 changes: 5 additions & 4 deletions MndpTray/MndpTray/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@

namespace MndpTray
{
internal static class Program
public static class Program
{
[STAThread]
private static void Main()
public static void Main()
{
string processName = System.Diagnostics.Process.GetCurrentProcess().ProcessName;
if (System.Diagnostics.Process.GetProcessesByName(processName).Length > 1)
Expand All @@ -24,10 +24,11 @@ private static void Main()
Log("-------------------< END >-------------------");
}

#region Fields
#region Fields

private static readonly bool LOG_FILE_IS_ENABLED = File.Exists(GetLogFileName("log"));
private static readonly object LOG_FILE_LOCK = new object();
private static readonly string LOG_FILE_NAME = GetLogFileName("log");
private static readonly bool LOG_FILE_IS_ENABLED = File.Exists(LOG_FILE_NAME);
#endregion Fields

#region Event Handlers
Expand Down
4 changes: 2 additions & 2 deletions MndpTray/MndpTray/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,5 +32,5 @@
// 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.5.3.0")]
[assembly: AssemblyFileVersion("1.5.3.0")]
[assembly: AssemblyVersion("1.6.0.0")]
[assembly: AssemblyFileVersion("1.6.0.0")]
Loading

0 comments on commit d965c8c

Please sign in to comment.