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 255e5bf..b3b6034 100644 Binary files a/MndpTray/MndpTray.Protocol/Properties/AssemblyInfo.cs and b/MndpTray/MndpTray.Protocol/Properties/AssemblyInfo.cs differ 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