IPAddress

IPAddress is a very small class in the System.Net namespace.  It's job is to just represent, well, an IP address.  It supports both IPv4 and IPv6 type addresses.

You can make new IP address either by supplying a byte array to the constructor, or using the IPAddress.Parse() (or IPAddress.TryParse()) method to get one from a string. Exceptions will be thrown if the IP address is malformed (either via strings or byte arrays).  When using the constructor, if you supply a byte array of exactly four bytes, it will assume you want an IPv4 address.

 

 

Please also note the static fields of IPAddress are very important when creating servers, all of them are read only.

  • Any - This tells a Socket to listen for connections on any network devices.  Which may be coming in locally or via a network
  • Loopback - This tells a Socket to listen for connections that are only coming in from the local machine (127.0.0.1)
  • Broadcast - This provides the broadcast IP address to a socket
  • None - This tells a Socket not to listen in for any connections

All of the fields above are for IPv4, but IPAddress has IPv6 versions of most of these static fields.

© 16BPP.net – Made using & love.
Back to Top of Page
This site uses cookies.