internal bool IsLocal(string host) {
int dot = host.IndexOf('.');
if (dot == -1) {
// No choice but to treat it as a host on the local domain
// This also covers 'localhost' and 'loopback'
return true;
}
// quick test for usual case
if (host == "127.0.0.1")
{
return true;
}
// test domain membership
if (string.Compare(m_fqdnMyDomain, 0, host, dot, m_fqdnMyDomain.Length, StringComparison.OrdinalIgnoreCase ) == 0)
{
return true;
}
// test for "127.###.###.###" without using regex
string[] ipParts = host.Split('.');
if (ipParts != null && ipParts.Length == 4 && ipParts[0] == "127")
{
int i;
for (i = 1; i < 4; i++)
{
switch (ipParts[i].Length)
{
case 3:
if (ipParts[i][2] < '0' || ipParts[i][2] > '9')
{
break;
}
goto case 2;
case 2:
if (ipParts[i][1] < '0' || ipParts[i][1] > '9')
{
break;
}
goto case 1;
case 1:
if (ipParts[i][0] < '0' || ipParts[i][0] > '9')
{
break;
}
continue;
}
break;
}
if (i == 4)
{
return true;
}
}
return false;
}