Skip to Main Content
C# Cookbook, 2nd Edition
book

C# Cookbook, 2nd Edition

by Jay Hilyard, Stephen Teilhet
January 2006
Intermediate to advanced content levelIntermediate to advanced
1184 pages
43h 23m
English
O'Reilly Media, Inc.
Content preview from C# Cookbook, 2nd Edition
This is the Title of the Book, eMatter Edition
Copyright © 2007 O’Reilly & Associates, Inc. All rights reserved.
792
|
Chapter 14: Web
StringBuilder addressList = new StringBuilder( );
// Get each IP address.
foreach(IPAddress address in addresses)
{
// Append it to the list.
addressList.AppendFormat("IP Address: {0};", address.ToString( ));
}
return addressList.ToString( );
}
// ...
// Writes "IP Address: 208.201.239.37;IP Address: 208.201.239.36;"
Console.WriteLine(HostName2IP("www.oreilly.com"));
Discussion
An IPHostEntry can associate multiple IP addresses with a single hostname via the
AddressList property. AddressList is an array of IPAddress objects, each of which
holds a single IP address. Once the
IPHostEntry is resolved, the AddressList can be
looped over using
foreach to create a string that shows all of the IP addresses for the
given hostname. If the entry cannot be resolved, a
SocketException is thrown.
See Also
See the “DNS Class,” “IPHostEntry Class,” and “IPAddress” topics in the MSDN
documentation.
14.3 Parsing a URI
Problem
You need to split a uniform resource identifier (URI) into its constituent parts.
Solution
Construct a System.Net.Uri object and pass the URI to the constructor. This class
constructor parses out the constituent parts of the URI and allows access to them via
the
Uri properties. You can then display the URI pieces individually, as shown in
Example 14-1.
Example 14-1. ParseURI ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

C# Cookbook

C# Cookbook

Joe Mayo
C# Cookbook

C# Cookbook

Stephen Teilhet, Jay Hilyard
Head First C#, 4th Edition

Head First C#, 4th Edition

Andrew Stellman, Jennifer Greene

Publisher Resources

ISBN: 0596100639Supplemental ContentCatalog PageErrata