GetHostAddresses
How do I use Get Host Addresses
Below are practical examples compiled from projects for learning and reference purposes
Featured Snippets
Line | Code | Ex.. |
---|---|---|
222 | IPAddress[] address = Dns.GetHostAddresses(hostName); | 1 |
File name: PingCloudRegions.cs
Copy
218 public static string ResolveHost(string hostName)
219 {
220 try
221 {
222 IPAddress[] address = Dns.GetHostAddresses(hostName);
223
224 if (address.Length == 1)
225 {
226 return address[0].ToString();
227 }
228
229 // if we got more addresses, try to pick a IPv4 one
230 for (int index = 0; index < address.Length; index++)
231 {
232 IPAddress ipAddress = address[index];
233 if (ipAddress != null)
234 {
235 string ipString = ipAddress.ToString();
236 if (ipString.IndexOf('.') >= 0)
237 {
238 return ipString;
239 }
240 }
241 }
242 }
243 catch (System.Exception e)
244 {
245 Debug.Log("Exception caught! " + e.Source + " Message: " + e.Message);
246 }
247
248 return String.Empty;
249 }
GetHostAddresses 145 lượt xem
Gõ tìm kiếm nhanh...