From d965c8c0e2af536e69fd028d6c09f69e837dfb6a Mon Sep 17 00:00:00 2001 From: xmegz Date: Fri, 15 Mar 2019 23:26:10 +0100 Subject: [PATCH] Protocol: 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) --- MndpTray/MndpService/Program.cs | 6 +- .../MndpService/Properties/AssemblyInfo.cs | 4 +- MndpTray/MndpTray.Protocol.Test/Program.cs | 44 ++++--- .../Properties/AssemblyInfo.cs | 6 +- .../MndpTray.Protocol.Test/packages.config | 2 +- .../MndpTray.Protocol/IMndpInterfaceInfo.cs | 6 + MndpTray/MndpTray.Protocol/MndpHostInfo.cs | 9 +- .../MndpTray.Protocol/MndpInterfaceInfo.cs | 10 +- MndpTray/MndpTray.Protocol/MndpMessage.cs | 42 +++++-- MndpTray/MndpTray.Protocol/MndpSender.cs | 1 + .../Properties/AssemblyInfo.cs | Bin 2996 -> 2996 bytes MndpTray/MndpTray.Protocol/package.nuspec | 4 +- MndpTray/MndpTray/Program.cs | 9 +- MndpTray/MndpTray/Properties/AssemblyInfo.cs | 4 +- MndpTray/MndpTray/Visual/ListForm.Designer.cs | 14 ++- MndpTray/MndpTray/Visual/ListForm.cs | 114 ++++++++++-------- MndpTray/MndpTray/Visual/ListForm.resx | 3 + README.md | 25 ++-- 18 files changed, 184 insertions(+), 119 deletions(-) diff --git a/MndpTray/MndpService/Program.cs b/MndpTray/MndpService/Program.cs index 2b1eeeb..989e260 100644 --- a/MndpTray/MndpService/Program.cs +++ b/MndpTray/MndpService/Program.cs @@ -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; @@ -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 diff --git a/MndpTray/MndpService/Properties/AssemblyInfo.cs b/MndpTray/MndpService/Properties/AssemblyInfo.cs index 0e87bd2..660c75f 100644 --- a/MndpTray/MndpService/Properties/AssemblyInfo.cs +++ b/MndpTray/MndpService/Properties/AssemblyInfo.cs @@ -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")] diff --git a/MndpTray/MndpTray.Protocol.Test/Program.cs b/MndpTray/MndpTray.Protocol.Test/Program.cs index fda9b46..4e79a46 100644 --- a/MndpTray/MndpTray.Protocol.Test/Program.cs +++ b/MndpTray/MndpTray.Protocol.Test/Program.cs @@ -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 ---"); } - -} + } +} \ No newline at end of file diff --git a/MndpTray/MndpTray.Protocol.Test/Properties/AssemblyInfo.cs b/MndpTray/MndpTray.Protocol.Test/Properties/AssemblyInfo.cs index 33fa5a8..b704d14 100644 --- a/MndpTray/MndpTray.Protocol.Test/Properties/AssemblyInfo.cs +++ b/MndpTray/MndpTray.Protocol.Test/Properties/AssemblyInfo.cs @@ -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("")] @@ -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")] diff --git a/MndpTray/MndpTray.Protocol.Test/packages.config b/MndpTray/MndpTray.Protocol.Test/packages.config index eb217a0..b12415e 100644 --- a/MndpTray/MndpTray.Protocol.Test/packages.config +++ b/MndpTray/MndpTray.Protocol.Test/packages.config @@ -1,4 +1,4 @@  - + \ No newline at end of file diff --git a/MndpTray/MndpTray.Protocol/IMndpInterfaceInfo.cs b/MndpTray/MndpTray.Protocol/IMndpInterfaceInfo.cs index 07fc40d..58aa33d 100644 --- a/MndpTray/MndpTray.Protocol/IMndpInterfaceInfo.cs +++ b/MndpTray/MndpTray.Protocol/IMndpInterfaceInfo.cs @@ -27,5 +27,11 @@ public interface IMndpInterfaceInfo /// /// 192.168.0.1 string UnicastAddress { get; } + + /// + /// Interface Ipv6 unicast address + /// + /// fe80::2d1f:d9f4:4c05:a200 + string UnicastIPv6Address { get; } } } \ No newline at end of file diff --git a/MndpTray/MndpTray.Protocol/MndpHostInfo.cs b/MndpTray/MndpTray.Protocol/MndpHostInfo.cs index 30e2cf6..31b868b 100644 --- a/MndpTray/MndpTray.Protocol/MndpHostInfo.cs +++ b/MndpTray/MndpTray.Protocol/MndpHostInfo.cs @@ -71,7 +71,9 @@ public List 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) { @@ -79,10 +81,13 @@ public List InterfaceInfos 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) { diff --git a/MndpTray/MndpTray.Protocol/MndpInterfaceInfo.cs b/MndpTray/MndpTray.Protocol/MndpInterfaceInfo.cs index d05f31f..4ce23bf 100644 --- a/MndpTray/MndpTray.Protocol/MndpInterfaceInfo.cs +++ b/MndpTray/MndpTray.Protocol/MndpInterfaceInfo.cs @@ -32,6 +32,12 @@ public class MndpInterfaceInfo : IMndpInterfaceInfo /// 192.168.0.1 public String UnicastAddress { get; } + /// + /// Interface Ipv6 unicast address + /// + /// fe80::2d1f:d9f4:4c05:a200 + public String UnicastIPv6Address { get; } + #endregion Props #region Methods @@ -43,12 +49,14 @@ public class MndpInterfaceInfo : IMndpInterfaceInfo /// Interface name /// Interface mac address 12 hexdigit /// Interface unicast address - public MndpInterfaceInfo(string broadcastAddress, string interfaceName, string macAddress, string unicastAddress) + /// Interface Ipv6 unicast address + 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 diff --git a/MndpTray/MndpTray.Protocol/MndpMessage.cs b/MndpTray/MndpTray.Protocol/MndpMessage.cs index 8524811..bad2a49 100644 --- a/MndpTray/MndpTray.Protocol/MndpMessage.cs +++ b/MndpTray/MndpTray.Protocol/MndpMessage.cs @@ -1,6 +1,7 @@ using System; using System.Collections.Generic; using System.IO; +using System.Net; using System.Net.NetworkInformation; using System.Text; @@ -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; @@ -26,6 +28,7 @@ public class MndpMessage #endregion Consts #region Props + /// /// Sender board name /// @@ -41,6 +44,11 @@ public class MndpMessage /// public string InterfaceName { get; set; } + /// + /// Sender unicast IPv6 address + /// + public string UnicastIPv6Address { get; set; } + /// /// Sender mac address /// @@ -82,7 +90,7 @@ public class MndpMessage public TimeSpan Uptime { get; set; } /// - /// Sender software version + /// Sender software version /// public string Version { get; set; } @@ -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; } @@ -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(); } @@ -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() { @@ -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; } } @@ -285,7 +303,7 @@ protected class Tlv /// Record length /// public ushort Length { get; set; } - + /// /// Record vlue /// @@ -589,7 +607,7 @@ public class MndpMessageEx : MndpMessage, ICloneable public DateTime ReceiveDateTime { get; set; } /// - /// Sender unicast IPv4 address + /// Sender unicast IPv4 address /// public string UnicastAddress { get; set; } @@ -599,13 +617,14 @@ public class MndpMessageEx : MndpMessage, ICloneable /// /// AA:BB:CC:DD:EE:FF /// - public string MacAddressDelimited { + public string MacAddressDelimited + { get { if (this.MacAddress == null) return null; StringBuilder sb = new StringBuilder(); - - for(int i=0;i 0) sb.Remove(sb.Length - 1, 1); return sb.ToString(); + } + } - } } #endregion Props #region Methods @@ -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(); diff --git a/MndpTray/MndpTray.Protocol/MndpSender.cs b/MndpTray/MndpTray.Protocol/MndpSender.cs index 0388be8..6a67092 100644 --- a/MndpTray/MndpTray.Protocol/MndpSender.cs +++ b/MndpTray/MndpTray.Protocol/MndpSender.cs @@ -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()); } diff --git a/MndpTray/MndpTray.Protocol/Properties/AssemblyInfo.cs b/MndpTray/MndpTray.Protocol/Properties/AssemblyInfo.cs index 255e5bfc255b29e2df9a9703c307187f9e0e550d..b3b6034a4182922446a9fde6ae9a788a5278f88e 100644 GIT binary patch delta 38 ocmdlYzD0b42REx3gC2vyWMA%J5ikqHV^CtyWQb+pW#D1}0HGxYHUIzs delta 38 pcmdlYzD0b42RExJgC2wNWMA%J5ikqLGhk3+&}4{Z;AP-q005zJ208!$ diff --git a/MndpTray/MndpTray.Protocol/package.nuspec b/MndpTray/MndpTray.Protocol/package.nuspec index d361dc0..9b7b2d2 100644 --- a/MndpTray/MndpTray.Protocol/package.nuspec +++ b/MndpTray/MndpTray.Protocol/package.nuspec @@ -14,12 +14,12 @@ https://raw.githubusercontent.com/xmegz/MndpTray/master/MndpTray/MndpTray/Images/favicon.ico false - Mikrotik Neighbor Discovery Protocol + Mikrotik Neighbor Discovery Protocol - Network Discovery IMndpHostInfo InterfaceInfo also interface Copyright © 2018 - Mikrotik Discovery Protocol + Mikrotik Discovery Protocol Network Udp Broadcast Windows Routeros Mndp