mirror of
https://github.com/TalAloni/SMBLibrary.git
synced 2025-05-28 16:29:51 +02:00
Improved NetBIOS name server implementation
This commit is contained in:
parent
dd8e867693
commit
0241d5c055
4 changed files with 92 additions and 35 deletions
54
SMBServer/NetworkInterfaceHelper.cs
Normal file
54
SMBServer/NetworkInterfaceHelper.cs
Normal 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;
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue