static public IPAddress localAddress {
get {
if (mLocalAddress == null) {
#if UNITY_IPHONE
NetworkInterface[] nis = NetworkInterface.GetAllNetworkInterfaces();
foreach (NetworkInterface ni in nis) {
IPInterfaceProperties IPInterfaceProperties = ni.GetIPProperties();
UnicastIPAddressInformationCollection UnicastIPAddressInformationCollection = IPInterfaceProperties.UnicastAddresses;
foreach (UnicastIPAddressInformation UnicastIPAddressInformation in UnicastIPAddressInformationCollection) {
if (UnicastIPAddressInformation.Address.AddressFamily == AddressFamily.InterNetwork) {
mLocalAddress = UnicastIPAddressInformation.Address;
break;
}
}
}
#else
mLocalAddress = IPAddress.Loopback;
try
{
IPHostEntry ent = Dns.GetHostEntry(Dns.GetHostName());
foreach (IPAddress ip in ent.AddressList)
{
if (IsValidAddress(ip))
{
mLocalAddress = ip;
break;
}
}
}
#if DEBUG
catch (System.Exception ex)
{
System.Console.WriteLine("TNTools.LocalAddress: " + ex.Message);
}
#else
catch (System.Exception) {}
#endif
#endif
}
return mLocalAddress;
}
}