ASN.1 IPAddress type implementation

Namespace:  SnmpSharpNet
Assembly:  SnmpSharpNet (in SnmpSharpNet.dll) Version: 0.5.0.0 (0.5.0.0)

Syntax

         
 C#  Visual Basic  Visual C++ 
public class IpAddress : OctetString, IComparable<IPAddress>, 
	IComparable<IpAddress>
Public Class IpAddress _
	Inherits OctetString _
	Implements IComparable(Of IPAddress), IComparable(Of IpAddress)
public ref class IpAddress : public OctetString, 
	IComparable<IPAddress^>, IComparable<IpAddress^>

Members

               
 All Members  Constructors   Fields   Properties   Methods  
 Public

 Protected
 Instance

 Static 
 Declared

 Inherited
 XNA Framework Only 

 .NET Compact Framework Only 

 MemberDescription
IpAddress()()()
Constructs a default object with a length of zero. See the super class constructor for more details.
IpAddress(IpAddress)
Copy constructor. Constructs a duplicate object based on the passed application string object.
IpAddress(OctetString)
Copy constructor based on the base class.
IpAddress(array<Byte>[]()[])
Constructs an Application String with the passed data. The data is managed by the base class.
IpAddress(IPAddress)
Construct the IpAddress class from supplied IPAddress value.
IpAddress(String)
Constructs the class and initializes the value to the supplied IP address. See comments in Set(String) method for details.
IpAddress(UInt32)
Constructor
Append(array<Byte>[]()[])
Append contents of the byte array to the class value. If class value is length 0, byte array content is set as the class value.
(Inherited from OctetString.)
Append(String)
Append string value to the OctetString class. If current class content is length 0, new string value is set as the value of this class. Class assumes that string value is UTF8 encoded.
(Inherited from OctetString.)
BuildMaskFromBits(Int32)
Build a subnet mask from bit count value
ClassA
Class A IP address
ClassB
Class B IP address
ClassC
Class C IP address
ClassD
Class D IP address
ClassE
Class E IP address
Clone()()()
Create a new object that is a duplicate of the current object.
(Overrides OctetString..::.Clone()()().)
CompareTo(IpAddress)
Compare two IpAddress classes
CompareTo(IPAddress)
Compare class contents with the address stored in the supplied IPAddress class.
decode(array<Byte>[]()[], Int32)
Decode ASN.1 encoded IP address value.
(Overrides OctetString..::.decode(array<Byte>[]()[], Int32).)
encode(MutableByte)
BER encode OctetString variable.
(Inherited from OctetString.)
Equals(Object)
Compare 2 IpAddress objects.
(Overrides OctetString..::.Equals(Object).)
Explicit(IpAddress)
Allow explicit cast of the class as System.Net.IPAddress class.
GetBroadcastAddress(IpAddress)
Returns broadcast address for the objects IP and supplied subnet mask
GetClass()()()
Return network class of the IP address
GetHashCode()()()
Return hash representing the value of this object
(Overrides OctetString..::.GetHashCode()()().)
GetMaskBits()()()
Returns number of subnet bits in the mask.
GetSubnetAddress(IpAddress)
Return subnet address of the IP address in this object and supplied subnet mask
GetType()()()
Gets the Type of the current instance.
(Inherited from Object.)
Increment(UInt32)
Increment IP address contained in the object by specific number and return the result as a new class.
InvalidClass
Invalid IP address class
Invert()()()
Inverts IP address value. All 0s are converted to 1s and 1s to 0s
IsValidMask()()()
Checks if the value of the object is a valid subnet mask
Item[([(Int32])])
Indexed access to the OctetString class data members.
CopyC#
OctetString os = new OctetString("test");
for(int i=0;i<=os.Length;i++) {
 Console.WriteLine("{0}",os[i]);
}
(Inherited from OctetString.)
Length
Get length of the internal byte array. 0 if byte array is undefined or zero length.
(Inherited from OctetString.)
NetworkMask()()()
Returns network mask for the class value
Reset()()()
Reset internal buffer to null.
(Inherited from OctetString.)
ReverseByteOrder(UInt32)
Reverse int value byte order. Static function in IPAddress class doesn't work the way I expected it (didn't troubleshoot)
Set(String)
Sets the class value to the IP address parsed from the string parameter.
(Overrides OctetString..::.Set(String).)
Set(UInt32)
Set class value from 32-bit unsigned integer value representation of the IP address value
Set(Byte)
Set class value to an array 1 byte long and set the value to the supplied argument.
(Inherited from OctetString.)
Set(array<Byte>[]()[])
Set class value from the argument byte array. If byte array argument is null or length == 0, internal OctetString buffer is set to null.
(Inherited from OctetString.)
Set(Int32, Byte)
Set value at specified position to the supplied value
(Inherited from OctetString.)
ToArray()()()
Convert the OctetString class to a byte array. Internal class data buffer is *copied* and not passed to the caller.
(Inherited from OctetString.)
ToHexString()()()
Return string formatted hexadecimal representation of the objects value.
(Inherited from OctetString.)
ToMACAddressString()()()
Utility function to print a MAC address (binary string of 6 byte length.
(Inherited from OctetString.)
ToString()()()
Returns the application string as a dotted decimal represented IP address.
(Overrides OctetString..::.ToString()()().)
ToUInt32()()()
Network byte order IP address
Type
Return ASN.1 type of the object stored in this or derived class.
(Inherited from AsnType.)
Valid
Returns true if object contains a valid IP address value.

Remarks

You can assign the IP address value to the class using: A string value representing the IP address in dotted decimal notation:
CopyC#
IpAddress ipaddr = new IpAddress("10.1.1.1");
A string value representing the hosts domain name:
CopyC#
IpAddress ipaddr = new IpAddress("this.ismyhost.com");
Another IpAddress class:
CopyC#
IpAddress first = new IpAddress("10.1.1.2");
IpAddress second = new IpAddress(first);
Or from the System.Net.IPAddress:
CopyC#
IPAddress addr = IPAddress.Any;
IpAddress ipaddr = new IpAddress(addr);
You can check if the IpAddress class contains a valid value by calling:
CopyC#
IpAddress ipaddr = new IpAddress("10.1.1.3");
if( ! ipaddr.Valid ) {
  Console.WriteLine("Invalid IP Address value.");
  return;
}
There are other operations you can perform with the IpAddress class. For example, let say you retrieved an IP address and subnet mask from an SNMP agent and wish to scan the subnet for other hosts that can be managed. You could do this: IpAddress host = SomehowRetrieveIPAddress(); IpAddress mask = SomehowRetrieveSubnetMask(); IpAddress subnetAddr = host.GetSubnetAddress(mask); IpAddress broadcastAddr = host.GetBroadcastAddress(mask); IpAddress host = (IpAddress)subnetAddr.Clone(); while( host.CompareTo(broadcastAddr) != 0 ) { host = host.Increment(1); // increment IP address by one if( ! host.Equals(broadcastAddr) ) ScanHostInWhateverWayYouLike(host); }

Inheritance Hierarchy

System..::.Object
  SnmpSharpNet..::.AsnType
    SnmpSharpNet..::.OctetString
      SnmpSharpNet..::.IpAddress

See Also