Get Subnet Mask : IP Address « Network « C# / C Sharp

Home
C# / C Sharp
1.2D Graphics
2.Class Interface
3.Collections Data Structure
4.Components
5.Data Types
6.Database ADO.net
7.Date Time
8.Design Patterns
9.Development Class
10.Event
11.File Stream
12.Generics
13.GUI Windows Form
14.Internationalization I18N
15.Language Basics
16.LINQ
17.Network
18.Office
19.Reflection
20.Regular Expressions
21.Security
22.Services Event
23.Thread
24.Web Services
25.Windows
26.Windows Presentation Foundation
27.XML
28.XML LINQ
C# / C Sharp » Network » IP AddressScreenshots 
Get Subnet Mask
        
/*

Copyright (c) 2010 Jean-Paul Mikkers

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.

*/
using System;
using System.Collections.Generic;
using System.Net;
using System.Net.NetworkInformation;
using System.Net.Sockets;
using System.Text;
using System.IO;

namespace CodePlex.JPMikkers.DHCP
{
    public class Utils
    {

        public static IPAddress GetSubnetMask(IPAddress address)
        {
            foreach (NetworkInterface adapter in NetworkInterface.GetAllNetworkInterfaces())
            {
                foreach (UnicastIPAddressInformation unicastIPAddressInformation in adapter.GetIPProperties().UnicastAddresses)
                {
                    if (unicastIPAddressInformation.Address.AddressFamily == AddressFamily.InterNetwork)
                    {
                        if (address.Equals(unicastIPAddressInformation.Address))
                        {
                            return unicastIPAddressInformation.IPv4Mask;
                        }
                    }
                }
            }
            throw new ArgumentException(string.Format("Can't find subnetmask for IP address '{0}'", address));
        }

    }
}

   
    
    
    
    
    
    
    
  
Related examples in the same category
1.IPAddress AddressFamily
2.Parse an IPAddress
3.Loopback IPAddress
4.Broadcast IPAddress
5.Any IPAddress
6.None IPAddress
7.IsLoopback IPAddress
8.IP Address parse, lookup IP Address parse, lookup
9.IPEndPoint sampleIPEndPoint sample
10.Get Host By Name, Get Host Name
11.Get Host Entry
12.Parse Host String
13.Get Current Ip Address
14.Get Host IP Address
15.Get IP address by query whatismyip.com
16.Get Local IP Address
17.IP to value
18.Get user IP from HttpContext
19.IP to Uint
20.UInt32 To IP Address
21.IP Address To UInt 32
22.Get IP address from notation (xxx.xxx.xxx.xxx) or hostname
23.Gets my local IP address (not necessarily external) and subnet mask
24.Returns true if the IPEndPoint supplied is on the same subnet as this host
25.Is Ip Address By Regular Expression
26.Checks if a given string is a valid IP address.
27.IP Address To NumberIP Address To Number
28.Get the description of a Enum value.
29.Get Available Socket Port
java2s.com  | Contact Us | Privacy Policy
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.