Improved NetBIOS name server implementation

This commit is contained in:
Tal Aloni 2017-02-04 01:23:49 +02:00
parent dd8e867693
commit 0241d5c055
4 changed files with 92 additions and 35 deletions

View file

@ -0,0 +1,54 @@
/* Copyright (C) 2014-2017 Tal Aloni <tal.aloni.il@gmail.com>. All rights reserved.
*
* You can redistribute this program and/or modify it under the terms of
* the GNU Lesser Public License as published by the Free Software Foundation,
* either version 3 of the License, or (at your option) any later version.
*/
using System;
using System.Collections.Generic;
using System.Net;
using System.Net.Sockets;
using System.Net.NetworkInformation;
using Utilities;
namespace SMBServer
{
public class NetworkInterfaceHelper
{
public static List<IPAddress> GetHostIPAddresses()
{
List<IPAddress> result = new List<IPAddress>();
foreach (NetworkInterface netInterface in NetworkInterface.GetAllNetworkInterfaces())
{
IPInterfaceProperties ipProperties = netInterface.GetIPProperties();
foreach (UnicastIPAddressInformation addressInfo in ipProperties.UnicastAddresses)
{
if (addressInfo.Address.AddressFamily == AddressFamily.InterNetwork)
{
result.Add(addressInfo.Address);
}
}
}
return result;
}
public static IPAddress GetSubnetMask(IPAddress ipAddress)
{
foreach (NetworkInterface netInterface in NetworkInterface.GetAllNetworkInterfaces())
{
IPInterfaceProperties ipProperties = netInterface.GetIPProperties();
foreach (UnicastIPAddressInformation addressInfo in ipProperties.UnicastAddresses)
{
if (addressInfo.Address.AddressFamily == AddressFamily.InterNetwork)
{
if (IPAddress.Equals(addressInfo.Address, ipAddress))
{
return addressInfo.IPv4Mask;
}
}
}
}
return null;
}
}
}