ASN.1 IPAddress type implementation
Namespace: SnmpSharpNetAssembly: SnmpSharpNet (in SnmpSharpNet.dll) Version: 0.9.1.0 (0.9.1)
Syntax
| C# |
|---|
[SerializableAttribute] public class IpAddress : OctetString, IComparable, ICloneable |
| Visual Basic |
|---|
<SerializableAttribute> _ Public Class IpAddress _ Inherits OctetString _ Implements IComparable, ICloneable |
| Visual C++ |
|---|
[SerializableAttribute] public ref class IpAddress : public OctetString, IComparable, ICloneable |
Remarks
You can assign the IP address value to the class using:
A string value representing the IP address in dotted decimal notation:
CopyC#
A string value representing the hosts domain name:
CopyC#
Another IpAddress class:
CopyC#
Or from the System.Net.IPAddress:
CopyC#
You can check if the IpAddress class contains a valid value by calling:
CopyC#
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);
}
Note: internally, IpAddress class holds the value in a byte array, network ordered format.
IpAddress ipaddr = new IpAddress("10.1.1.1");
IpAddress ipaddr = new IpAddress("this.ismyhost.com");
IpAddress first = new IpAddress("10.1.1.2"); IpAddress second = new IpAddress(first);
IPAddress addr = IPAddress.Any;
IpAddress ipaddr = new IpAddress(addr);IpAddress ipaddr = new IpAddress("10.1.1.3"); if( ! ipaddr.Valid ) { Console.WriteLine("Invalid IP Address value."); return; }
Inheritance Hierarchy
System..::..Object
SnmpSharpNet..::..AsnType
SnmpSharpNet..::..OctetString
SnmpSharpNet..::..IpAddress
SnmpSharpNet..::..AsnType
SnmpSharpNet..::..OctetString
SnmpSharpNet..::..IpAddress