473,473 Members | 2,141 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Getting the end of a domain name

Hello,

I want to get the right most name of the a domain name, for example:

if the domain is www.myweb.com , I want to get myweb.com
something.myweb.com --> myweb.com
www.myweb.com.au --> myweb.com.au
something.myweb.com.au --> myweb.com.au
www.myweb.tv --> myweb.tv
www.something.myweb.net --> myweb.net
my.test.myweb.ca --> myweb.ca

I want to know if there is a general rule, code or article regarding this
issue.
I tried the following code, but I am not convinced, because it is not
generic
public static string GetDomainName(string serverName ) {

if(!serverName.Contains(".")) {

return serverName.ToLower();

}

if(serverName.EndsWith(".co.uk")) {

return serverName.Substring(serverName.LastIndexOf(".", serverName.Length -
".co.uk".Length - 1) + 1).ToLower();

}

if(serverName.EndsWith(".com") || serverName.EndsWith(".net") ||
serverName.EndsWith(".org")) {

return serverName.Substring(serverName.LastIndexOf(".", serverName.Length -
5) + 1).ToLower();

}

return null;

}

Does any one have a better solution?
Adam Tibi
Feb 20 '06 #1
6 2099
Adam,
I'd take a look at the System.Uri class, which has some built-in properties
that simplify segmenting out the portions of a Uri. There may be additional
ways to do it that I'm not aware of.
Peter

--
Co-founder, Eggheadcafe.com developer portal:
http://www.eggheadcafe.com
UnBlog:
http://petesbloggerama.blogspot.com


"Adam Tibi" wrote:
Hello,

I want to get the right most name of the a domain name, for example:

if the domain is www.myweb.com , I want to get myweb.com
something.myweb.com --> myweb.com
www.myweb.com.au --> myweb.com.au
something.myweb.com.au --> myweb.com.au
www.myweb.tv --> myweb.tv
www.something.myweb.net --> myweb.net
my.test.myweb.ca --> myweb.ca

I want to know if there is a general rule, code or article regarding this
issue.
I tried the following code, but I am not convinced, because it is not
generic
public static string GetDomainName(string serverName ) {

if(!serverName.Contains(".")) {

return serverName.ToLower();

}

if(serverName.EndsWith(".co.uk")) {

return serverName.Substring(serverName.LastIndexOf(".", serverName.Length -
".co.uk".Length - 1) + 1).ToLower();

}

if(serverName.EndsWith(".com") || serverName.EndsWith(".net") ||
serverName.EndsWith(".org")) {

return serverName.Substring(serverName.LastIndexOf(".", serverName.Length -
5) + 1).ToLower();

}

return null;

}

Does any one have a better solution?
Adam Tibi

Feb 20 '06 #2
Thank you for the reply Peter, however, I did check it but I couldn't find
this specific requirment

Regards

"Peter Bromberg [C# MVP]" <pb*******@yahoo.nospammin.com> wrote in message
news:C6**********************************@microsof t.com...
Adam,
I'd take a look at the System.Uri class, which has some built-in
properties
that simplify segmenting out the portions of a Uri. There may be
additional
ways to do it that I'm not aware of.
Peter

--
Co-founder, Eggheadcafe.com developer portal:
http://www.eggheadcafe.com
UnBlog:
http://petesbloggerama.blogspot.com


"Adam Tibi" wrote:
Hello,

I want to get the right most name of the a domain name, for example:

if the domain is www.myweb.com , I want to get myweb.com
something.myweb.com --> myweb.com
www.myweb.com.au --> myweb.com.au
something.myweb.com.au --> myweb.com.au
www.myweb.tv --> myweb.tv
www.something.myweb.net --> myweb.net
my.test.myweb.ca --> myweb.ca

I want to know if there is a general rule, code or article regarding this
issue.
I tried the following code, but I am not convinced, because it is not
generic
public static string GetDomainName(string serverName ) {

if(!serverName.Contains(".")) {

return serverName.ToLower();

}

if(serverName.EndsWith(".co.uk")) {

return serverName.Substring(serverName.LastIndexOf(".",
serverName.Length -
".co.uk".Length - 1) + 1).ToLower();

}

if(serverName.EndsWith(".com") || serverName.EndsWith(".net") ||
serverName.EndsWith(".org")) {

return serverName.Substring(serverName.LastIndexOf(".",
serverName.Length -
5) + 1).ToLower();

}

return null;

}

Does any one have a better solution?
Adam Tibi

Feb 20 '06 #3
Hi,

Save your primary domain name (myweb) globally. Get the host name with HTTP_HOST server variable and use substring function

e.g.

string tct = @"www.something.myweb.net.au";
MessageBox.Show(tct.Substring(tct.IndexOf("myweb") ));

Will display out as myweb.net.au

Hope this might help you...

Vinu



"Adam Tibi" <ad*******@nospam.com> wrote in message news:%2****************@TK2MSFTNGP09.phx.gbl...
Hello,

I want to get the right most name of the a domain name, for example:

if the domain is www.myweb.com , I want to get myweb.com
something.myweb.com --> myweb.com
www.myweb.com.au --> myweb.com.au
something.myweb.com.au --> myweb.com.au
www.myweb.tv --> myweb.tv
www.something.myweb.net --> myweb.net
my.test.myweb.ca --> myweb.ca

I want to know if there is a general rule, code or article regarding this
issue.
I tried the following code, but I am not convinced, because it is not
generic
public static string GetDomainName(string serverName ) {

if(!serverName.Contains(".")) {

return serverName.ToLower();

}

if(serverName.EndsWith(".co.uk")) {

return serverName.Substring(serverName.LastIndexOf(".", serverName.Length -
".co.uk".Length - 1) + 1).ToLower();

}

if(serverName.EndsWith(".com") || serverName.EndsWith(".net") ||
serverName.EndsWith(".org")) {

return serverName.Substring(serverName.LastIndexOf(".", serverName.Length -
5) + 1).ToLower();

}

return null;

}

Does any one have a better solution?
Adam Tibi

Feb 20 '06 #4
Thank you Vinu,

The problem here is that I don't know the domain name in advance, I am going to get different domain names and I need to parse them, so this solution doesn't work because it assumes that I know the domain name in advance. I want a global solution that will get the last portion of any domain name.

ideas any one?
Regards
Adam Tibi
"vinu" <vi*********@googlemail.com> wrote in message news:e$*************@TK2MSFTNGP09.phx.gbl...
Hi,

Save your primary domain name (myweb) globally. Get the host name with HTTP_HOST server variable and use substring function

e.g.

string tct = @"www.something.myweb.net.au";
MessageBox.Show(tct.Substring(tct.IndexOf("myweb") ));

Will display out as myweb.net.au

Hope this might help you...

Vinu



"Adam Tibi" <ad*******@nospam.com> wrote in message news:%2****************@TK2MSFTNGP09.phx.gbl...
Hello,

I want to get the right most name of the a domain name, for example:

if the domain is www.myweb.com , I want to get myweb.com
something.myweb.com --> myweb.com
www.myweb.com.au --> myweb.com.au
something.myweb.com.au --> myweb.com.au
www.myweb.tv --> myweb.tv
www.something.myweb.net --> myweb.net
my.test.myweb.ca --> myweb.ca

I want to know if there is a general rule, code or article regarding this
issue.
I tried the following code, but I am not convinced, because it is not
generic
public static string GetDomainName(string serverName ) {

if(!serverName.Contains(".")) {

return serverName.ToLower();

}

if(serverName.EndsWith(".co.uk")) {

return serverName.Substring(serverName.LastIndexOf(".", serverName.Length -
".co.uk".Length - 1) + 1).ToLower();

}

if(serverName.EndsWith(".com") || serverName.EndsWith(".net") ||
serverName.EndsWith(".org")) {

return serverName.Substring(serverName.LastIndexOf(".", serverName.Length -
5) + 1).ToLower();

}

return null;

}

Does any one have a better solution?
Adam Tibi

Feb 21 '06 #5
As Peter tried to convey, there's probably a method in a class the framework
provides. The "long hand" way I did this in ASP can still be done using
ASP.NET...

* Get the URL as a string and trim white space from front and back
* Pass the trimmed string to a string reverse method
* Split the reversed string on the . character
* Get the value from the [0]th array indice
* Reverse that value and you get "com", "org", "aero", "name" or whatever

Note when we split a string an array is created. Simply get the value from
the [0]th indice as I indicate and reverse the value and you get what you
want.
<%= Clinton Gallagher
METROmilwaukee (sm) "A Regional Information Service"
NET csgallagher AT metromilwaukee.com
URL http://metromilwaukee.com/
URL http://clintongallagher.metromilwaukee.com/
"Adam Tibi" <ad*******@nospam.com> wrote in message
news:Ov**************@TK2MSFTNGP15.phx.gbl...
Thank you Vinu,

The problem here is that I don't know the domain name in advance, I am going
to get different domain names and I need to parse them, so this solution
doesn't work because it assumes that I know the domain name in advance. I
want a global solution that will get the last portion of any domain name.

ideas any one?
Regards
Adam Tibi
"vinu" <vi*********@googlemail.com> wrote in message
news:e$*************@TK2MSFTNGP09.phx.gbl...
Hi,

Save your primary domain name (myweb) globally. Get the host name with
HTTP_HOST server variable and use substring function

e.g.

string tct = @"www.something.myweb.net.au";
MessageBox.Show(tct.Substring(tct.IndexOf("myweb") ));
Will display out as myweb.net.au
Hope this might help you...

Vinu

"Adam Tibi" <ad*******@nospam.com> wrote in message
news:%2****************@TK2MSFTNGP09.phx.gbl...
Hello,

I want to get the right most name of the a domain name, for example:

if the domain is www.myweb.com , I want to get myweb.com
something.myweb.com --> myweb.com
www.myweb.com.au --> myweb.com.au
something.myweb.com.au --> myweb.com.au
www.myweb.tv --> myweb.tv
www.something.myweb.net --> myweb.net
my.test.myweb.ca --> myweb.ca

I want to know if there is a general rule, code or article regarding this
issue.
I tried the following code, but I am not convinced, because it is not
generic
public static string GetDomainName(string serverName ) {

if(!serverName.Contains(".")) {

return serverName.ToLower();

}

if(serverName.EndsWith(".co.uk")) {

return serverName.Substring(serverName.LastIndexOf(".",
serverName.Length -
".co.uk".Length - 1) + 1).ToLower();

}

if(serverName.EndsWith(".com") || serverName.EndsWith(".net") ||
serverName.EndsWith(".org")) {

return serverName.Substring(serverName.LastIndexOf(".",
serverName.Length -
5) + 1).ToLower();

}

return null;

}

Does any one have a better solution?
Adam Tibi


Feb 21 '06 #6
Thank you Clinton,

You are assuming that the extention is just one part like "org" or "net" but
it might be "com.au" or "co.uk" and I currently made a solution for the
extentions that I know but I wanted a generic solution that doesn't require
me to check .com.au, .com.lb, .co.uk, ca, net, org, us, info, etc...

I just wanted a general rule for this.

Regards,
Adam Tibi

"clintonG" <cs*********@REMOVETHISTEXTmetromilwaukee.com> wrote in message
news:eX**************@TK2MSFTNGP15.phx.gbl...
As Peter tried to convey, there's probably a method in a class the
framework provides. The "long hand" way I did this in ASP can still be
done using ASP.NET...

* Get the URL as a string and trim white space from front and back
* Pass the trimmed string to a string reverse method
* Split the reversed string on the . character
* Get the value from the [0]th array indice
* Reverse that value and you get "com", "org", "aero", "name" or whatever

Note when we split a string an array is created. Simply get the value from
the [0]th indice as I indicate and reverse the value and you get what you
want.
<%= Clinton Gallagher
METROmilwaukee (sm) "A Regional Information Service"
NET csgallagher AT metromilwaukee.com
URL http://metromilwaukee.com/
URL http://clintongallagher.metromilwaukee.com/
"Adam Tibi" <ad*******@nospam.com> wrote in message
news:Ov**************@TK2MSFTNGP15.phx.gbl...
Thank you Vinu,

The problem here is that I don't know the domain name in advance, I am
going to get different domain names and I need to parse them, so this
solution doesn't work because it assumes that I know the domain name in
advance. I want a global solution that will get the last portion of any
domain name.

ideas any one?
Regards
Adam Tibi
"vinu" <vi*********@googlemail.com> wrote in message
news:e$*************@TK2MSFTNGP09.phx.gbl...
Hi,

Save your primary domain name (myweb) globally. Get the host name with
HTTP_HOST server variable and use substring function

e.g.

string tct = @"www.something.myweb.net.au";
MessageBox.Show(tct.Substring(tct.IndexOf("myweb") ));
Will display out as myweb.net.au
Hope this might help you...

Vinu

"Adam Tibi" <ad*******@nospam.com> wrote in message
news:%2****************@TK2MSFTNGP09.phx.gbl...
Hello,

I want to get the right most name of the a domain name, for example:

if the domain is www.myweb.com , I want to get myweb.com
something.myweb.com --> myweb.com
www.myweb.com.au --> myweb.com.au
something.myweb.com.au --> myweb.com.au
www.myweb.tv --> myweb.tv
www.something.myweb.net --> myweb.net
my.test.myweb.ca --> myweb.ca

I want to know if there is a general rule, code or article regarding this
issue.
I tried the following code, but I am not convinced, because it is not
generic
public static string GetDomainName(string serverName ) {

if(!serverName.Contains(".")) {

return serverName.ToLower();

}

if(serverName.EndsWith(".co.uk")) {

return serverName.Substring(serverName.LastIndexOf(".",
serverName.Length -
".co.uk".Length - 1) + 1).ToLower();

}

if(serverName.EndsWith(".com") || serverName.EndsWith(".net") ||
serverName.EndsWith(".org")) {

return serverName.Substring(serverName.LastIndexOf(".",
serverName.Length -
5) + 1).ToLower();

}

return null;

}

Does any one have a better solution?
Adam Tibi

Feb 22 '06 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
by: Wm | last post by:
I'm totally clueless on this one -- I'm getting 3 copies of every Email (in plain text, not HTML as expected), from a single mail() line... Can anyone tell me what might be causing the duplicates??...
0
by: Buddy Ackerman | last post by:
I have an application where the client wants AD integration. The application requires that the user accounts reside in the app's database. The application is a (.NET) webservices based app where...
10
by: Peter Afonin | last post by:
Hello, I have a simple client-side form that is checking the domain availability on the domain registrar's server: <FORM action="https://www.webnames.ru/scripts/RegTimeSRS.pl" method="post">...
2
by: Scott M. Lyon | last post by:
I'm having some strange problems with a VB.NET application that I support. The application currently uses SystemInformation.UserName() and SystemInformation.UserDomainName() to determine who is...
32
by: paul | last post by:
HI! I keep on getting this error and I have tried different things but I am not sure how to send the expiring date. The error that I am getting in Firefox 1.5 is "Error: expires.toGMTString is...
5
by: Michael Howes | last post by:
I'm writing a utility to manage a machines *local* accounts in c# I am getting all the users in a specific Group just fine but when I want to get some of the information on each user from their...
0
by: Per0 | last post by:
Hi, I have problem getting all domains. My code looks like: _dirEntry.Path = "LDAP://RootDSE" _strRootDomain = "LDAP://" & _dirEntry.Properties("rootDomainNamingContext").Value.ToString()...
1
by: Chris White | last post by:
Here's my XML <?xml version="1.0" encoding="UTF-8"?> <results> <status code="ok"/> <report-bulk-users> <row principal-id="23859115" type="user"> <login>muser@domain.com</login> <name>My...
1
by: sbettadpur | last post by:
hello i am calling .exe file through my php script. i.e. using exec or system command, i am running exe file that exe file will create on txt file which contains who has logged into domain(i.e....
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
1
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.