private static String ExtractHostFromURL(String url)
{
// see RFC 1738
// remove ':' after protocol, e.g. http:
String sub = url.Substring(url.IndexOf(':') + 1);
// extract host from Common Internet Scheme Syntax, e.g. http://
if (sub.IndexOf("//") != -1)
{
sub = sub.Substring(sub.IndexOf("//") + 2);
}
// first remove port, e.g. http://test.com:21
if (sub.LastIndexOf(':') != -1)
{
sub = sub.Substring(0, sub.LastIndexOf(':'));
}
// remove user and password, e.g. http://john:[email protected]
sub = sub.Substring(sub.IndexOf(':') + 1);
sub = sub.Substring(sub.IndexOf('@') + 1);
// remove local parts, e.g. http://test.com/bla
if (sub.IndexOf('/') != -1)
{
sub = sub.Substring(0, sub.IndexOf('/'));
}
return sub;
}