Getting the domain name

Hello,

We have a fairly simple redirect script a url is entered, and even tho there are 
directions to not enter the "http://www" sometimes we get it or "http://"... 
what is the simplest method to extract just the domain name if a 
"http://www.somedomain_name.com" or "http://somedomain_name.com" is enter so we 
can extract just the "somedomain_name.com"

thx's

-- 
Mike<mickalo>Blezien
=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
Thunder Rain Internet Publishing
Providing Internet Solutions that work!
http://www.thunder-rain.com
Web Hosting
http://www.justlightening.net
Tel:  1(985)902-8484
MSN: mickalo@bellsouth.net
=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=


0
mickalo
7/14/2003 4:37:57 PM
perl.beginners.cgi 3838 articles. 0 followers. Follow

5 Replies
499 Views

Similar Articles

[PageSpeed] 28

On Monday, Jul 14, 2003, at 09:37 US/Pacific, Mike Blezien wrote:

> Hello,
>
> We have a fairly simple redirect script a url is entered, and even tho 
> there are directions to not enter the "http://www" sometimes we get it 
> or "http://"... what is the simplest method to extract just the domain 
> name if a "http://www.somedomain_name.com" or 
> "http://somedomain_name.com" is enter so we can extract just the 
> "somedomain_name.com"

The simplest of re's I can think of is

	#------------------------
	#
	sub simple_get_domain
	{
		my ($string) = @_;
		my $some_dom;
		
		if ( $string =~ m!http://www.(.*)! ) {
			$some_dom = $1;
		}elsif ( $string =~ m!http://(.*)! ) {
			
			$some_dom = $1;
		}
		$some_dom;
	
	} # end of simple_get_domain

but this is merely a string parser -
and is not really gonna make sure that the
$some_dom returned is kosher...

The squirelly part of course are things like:

	http://foo.bar.com:12345/uri_path_stuff_here
or

	http://127.0.0.1/

I start that part with something like

	sub parse_url
	{
		my ($me,$url) = @_;
	
		my($schema, $host_port, $uri ) = ($url =~ m!^([^:]+)://([^/]+)(.*)$!);
	
	} # end of parse_url

	sub get_host_port
	{
		my ($me,$host_port) = @_;

		my ($host,$port) = ($host_port =~ m/([^:]+):([^:]+)/) ?
			($1,$2) : ($host_port, '');
	}

And then the validation part gets into either working
backwards from the TLD - top level domain - or
trying to figure out which part of the string is
the host part..... try to remember that

	nas.nasa.gov

IS the domain name, not a host and domain component....


ciao
drieux

---

0
drieux
7/14/2003 9:45:41 PM
Mike Blezien wrote:
> Hello,
> 
> We have a fairly simple redirect script a url is entered, and even tho 
> there are directions to not enter the "http://www" sometimes we get it 
> or "http://"... what is the simplest method to extract just the domain 
> name if a "http://www.somedomain_name.com" or 
> "http://somedomain_name.com" is enter so we can extract just the 
> "somedomain_name.com"
> 

May want to have a look at the URI module.  Not sure if it is part of 
any particular package, I think it may be part of the stock RH 9.0 
install, so I would have a look in @INC and/or CPAN.

http://danconia.org

0
wiggins
7/14/2003 11:30:52 PM
> We have a fairly simple redirect script a url is entered, and even tho
> there are directions to not enter the "http://www" sometimes we get it
> or "http://"... what is the simplest method to extract just the domain
> name if a "http://www.somedomain_name.com" or
> "http://somedomain_name.com" is enter so we can extract just the
> "somedomain_name.com"

Hmm... I've had to do something similar this in the past when writing a
'parking page' for multiple names that where sent to the same IP. The IP
hosted a perl script that needed to see which domain had been referred to
the IP via the dynamic DNS server.

Basically I'd looked into all kind of packages and stuff, but the script ran
quickest by just doing the following

my $domain = $ENV{'SERVER_NAME'};
$domain =~ s/^http:\/\/www.//;
$domain =~ s/^http:\/\///;

Regardless of what they enter, you should end up with just 'domain.tld' or
'sub.domain.tld' if the name being forward using sub domains - like many
ISPs do for free hosting space.

Hope that helps...

~Keith Szlamp
http://szlamp.com


0
keith
7/17/2003 10:41:58 AM
--- Keith Szlamp <keith@szlamp.com> wrote:
> my $domain = $ENV{'SERVER_NAME'};
> $domain =~ s/^http:\/\/www.//;
> $domain =~ s/^http:\/\///;
> 
> Regardless of what they enter, you should end up with just 'domain.tld' or
> 'sub.domain.tld' if the name being forward using sub domains - like many
> ISPs do for free hosting space.

To be honest, while I don't know a simple answer for this, the reality is that this answer doesn't
work very well.  People can easily type stuff like:

  http://blogs.server.somehost.co.uk/
  http://foo.co.uk/
  https://www.host.com/

There are plenty of other things I could toss out that cause issues here.

Cheers,
Ovid

=====
Hire me!                   http://users.easystreet.com/ovid/personal/resume.html
Silence is Evil            http://users.easystreet.com/ovid/philosophy/indexdecency.htm
Ovid                       http://www.perlmonks.org/index.pl?node_id=17000
Web Programming with Perl  http://users.easystreet.com/ovid/cgi_course/

__________________________________
Do you Yahoo!?
SBC Yahoo! DSL - Now only $29.95 per month!
http://sbc.yahoo.com
0
poec
7/17/2003 8:17:49 PM
Ovid Says >
To be honest, while I don't know a simple answer for this, the reality is
that this answer doesn't work very well. People can easily type stuff like:

  http://blogs.server.somehost.co.uk/
  http://foo.co.uk/
  https://www.host.com/

Keith Says >
Hmm... I agree with you. It's the same old programmers dilemma, do you go
overboard and try to cater for every eventual possibility and trap every
error or do you just build something quick that works and develop it later
if you need to? Personally I always base that solution on the critical
nature of project. Parking pages was my application... hmm... and I think no
one will die if the junk traffic isn't captured and my directory and pop-ups
aren't served to a few web surfers. But getting back on topic if you run
those URIs through the script mentioned previously then you'd get...

blogs.server.somehost.co.uk
foo.co.uk

Which I assume is what he's basically after, isn't it? and unless he's
running an SSL server he'll never capture the https:// port anyhow. All I'm
saying is, as a quick fix the 3 liner worked great and will probably suffice
in most cases, if he gets problems he can always go in hack the script to
work better. From experience, the majority of traffic is going be prefixed
with http://www. or just http:// anyhow.

Regards, Keith

0
keith
7/17/2003 9:07:14 PM
Reply:

Similar Artilces:

ContextType.Domain gets PrincipalServerDownException unless specify domain controller by name
Hi There Just trying out the new System.DirectoryServices.AccountManagement with Visual Studio 2008 Express Edition.  My scenario:  -Client Windows XP joined to domain -One Windows Server 2003 domain controller / IIS  I want to get the full name of the logged in user. This works if I specify the domain controller name. Specifying the domain name (either fully qualified or NETBIOS) does not work. Any suggestions ? Am I doing something wrong here.   My working code is like this:   Dim domainContext As New System.DirectoryServices.AccountManagement.PrincipalCo...

Get domain name
I am tryng to find the simplest way to get the domain name of the site that some code is running under, on the web I find this: Environment.UserDomainName.ToString Which always returns my server hostname... not what I want..Ask One/Answer One.  maybe something like dis? string url = Request.Url.AbsolutePath; orRequest.Url.DnsSafeHost +Lvl FIVE THOUSAND DRAGON MASTER SOFTWARE ENGINEER my friends call me MOI You can get the hostname from a HttpRequest, e.g.  Page.Request.Url.Host if you are executing in a aspx page.The problem is that since the site may be running with se...

Getting a domain name.
Where would you buy a .com domain name from? On Thu, 15 Sep 2011 14:18:54 +0000, Arthur wrote: > Where would you buy a .com domain name from? There are a whole lot of choices most of which are good. We have settled on Domain Monger. I use www.networksolutions.com, that way you actually own the domain, you have to be careful with some third party domain registration companies as they register the domain on your behalf. but set themselves up as the owner. So if you want to move things or mange the domain you have to deal with them. and trying to get the ownership becomes a h...

Getting Domain Name
How do you capture the domain name from within PB? I assume win api is needed, does anyone know the call? Mike, Since no one has answered you, you might check out FUNCky for PB... the FUNCky.Domain() method returnes the logged in Domain name. Its a little annoying to do through the Win Api so you might save some headaches using an add-on. -Dirk [FUNCky Developer] [dLESKO Inc.] <-- Got FUNCky? Get it now at http://www.funcky.com. FUNCky Rocks! --> Here's another easy way -- using the Microsoft Scripting Host (installed with Win98 and W2K, and also avai...

How to get domain user's first name, last name and e-mail address
Hi everyone, I am able to retrieve the domain/user ID by setting <authentication mode="Windows"/> in the Web.config file, and with the following code in my Default.aspx.,cs page: string strName = Request.ServerVariables["AUTH_USER"]; I would also like to retrieve the users first name, last name and e-mail address from their domain profile, if possible.  Can anyone help me with a code example?  I'm somewhat new to C#/.NET/OOP so if you have it in "C# for Dummies" format, I would be very thankful! Thanks in advance for any help that i...

Need to get domain name
I need to get the user domain as well as the user name. Getting the name is easy but can't find anything that gets me the domain. .Net has Environment.UserDomainName() Does PB have anything similar or does anyone know the API call that will get me what I need? thanks Try this: http://msdn.microsoft.com/library/en-us/netmgmt/netmgmt/netwkstausergetinfo.asp?frame=true <Darren> wrote in message news:42483636.25b8.1681692777@sybase.com... > I need to get the user domain as well as the user name. > Getting the name is easy but can't find anything that gets ...

getting only domain names from list
Hello all, I have a list from a logfile that has urls browsed. I have to extract all domainnames considering subdomains as the same as the domainnames eg @list = qw( yahoo.com mail.yahoo.com hotmail.com yahoo.co.in cnn.co.uk news.cnn.co.uk) I would like to write a function that will give me only the unique domainnames @uniq = qw(yahoo.com hotmail.com yahoo.co.in cnn.co.uk) I have a feeling someone would have done this before Thanx Ramprasad A Padmanabhan ...

Getting the right most of the 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.comsomething.myweb.com -->  myweb.comwww.myweb.com.au -->  myweb.com.ausomething.myweb.com.au -->  myweb.com.auwww.myweb.tv --> myweb.tvwww.something.myweb.net --> myweb.netmy.test.myweb.ca --> myweb.caI 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 genericpublic static string GetDomainName(string serverName ) {if(!serverName.Contain...

get parked domain name
--part1_12e.ed205a2.29d39e2c_boundary Content-Type: text/plain; charset="US-ASCII" Content-Transfer-Encoding: 7bit I just parked a domain name a few days ago and now I want to use it. But I can't seem to access it with the $ENV variables. I've tried $ENV{'SERVER_NAME'} Which I thought would do the trick! Anyone have any tricks up their sleeve? Thanks Tricia --part1_12e.ed205a2.29d39e2c_boundary-- ...

Domain name forwarding
HiI have written a portal content management system, so that different users have different sites such as:www.portalsite.com/default.aspx?SiteID=1www.portalsite.com/default.aspx?SiteID=2       etc. I have managed to URL rewrite, in the global.asax, to give friendly URLs such as:www.portalsite.com/user01www.portalsite.com/user02 However some users have their own registered domain names which they can forward to their portal site.  For example a user may have 'www.mydomainname.com' (hosted with another ISP) which they forward to point to their portal address ...

How to get full domain name ?
I have some function to fetch domain name : /////////// --- start const NERR_Success = 0; function NetWkstaGetInfo(ServerName: LPWSTR; Level: DWORD; BufPtr: Pointer): Longint; stdcall; external 'netapi32.dll' Name 'NetWkstaGetInfo'; function GetNetParam(AParam: Integer): string; var PBuf: LPWKSTA_INFO_100; Res: LongInt; begin Result := ''; Res := NetWkstaGetInfo(nil, 100, @PBuf); if Res = NERR_Success then begin case AParam of 0: Result := string(PBuf^.wki100_computername); 1: Result := string(PBuf^.wki100_lan...

get domain only with CGI or URI modules
------_=_NextPart_001_01C2D6AA.EBBB4BE0 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable Hello,=20 =20 Does anyone know of a quick/easy/fast way to to get the domain out of a = url? =20 For instance if I do : $url =3D $cgi->url(); =20 I'll get, say http://joe.mama.com/so/isyour.cgi?mother =20 I know I can use URI module to get the scheme (http, https, ftp, etc) = from that What I need to grab out of that example is the domain only, ( mama.com ) = just the part that one would register with a registrar, not any = sub...

cheapest way to get a domain name?
I have an idea for a domain name, and I want to grab it before someone else gets it. I determined that it is available, but before I spend $14 at one place just to buy it, I figure there has got to be a cheaper place that sells them. I am not planning on actually hosting anything in the next few months at this new domain name, so I am not interested in going through my host (who hosts my current domain, www.middletree.net) So where's the cheapest place to go? Wandering aimlessly around grc.techtalk, I heard middletree mention: > I have an idea for a domain name, and I want ...

Web resources about - Getting the domain name - perl.beginners.cgi

The Moral Blame for the Colorado Springs Shootings
WASHINGTON Inflammatory rhetoric inflames. Words extreme language and overheated representations have consequences. The killer bears the ultimate ...

Whales under threat as climate change impacts migration
Puerto López (Ecuador) (AFP) - The sight of thousands of whales surfacing, jumping and playing off the coast of South America as they migrate ...

Juneau Mayor Found Dead: Newly Elected Stephen ‘Greg’ Fisk Found In Alaska Home
Alaska police are investigating the mysterious death of newly elected Juneau mayor Stephen “Greg” Fisk after he was found dead inside his Alaska ...

Facebook's CEO and wife to give 99 percent of shares to their new foundation
Reuters Facebook's CEO and wife to give 99 percent of shares to their new foundation Reuters SAN FRANCISCO Mark Zuckerberg will put 99 percent ...

The 10 funniest 'Star Wars' spoofs of all time
Star Wars is a space fantasy, a galactic fairy tale, a Skywalker family soap opera and a classic good vs. evil adventure story with mythological ...

Google removes Chrome's notification center because nobody used it
As promised in October, Google has ditched Chrome's desktop notification center in its latest update, released today. The company first introduced ...

Yahoo to consider sale of core Internet business and future of Marissa Mayer, says source
San Francisco (By Amrutha Penumudi in Bengaluru for Reuters) — The board of Yahoo Inc is weighing a sale of its core Internet business when it ...

Rosa Parks was a radical, lifelong black liberation activist, not a "meek seamstress"
Jeanne Theoharis, an academic who wrote the biography The Rebellious Life of Mrs. Rosa Parks , reminds us that the historical account of Rosa ...

Samsung Internet For Gear VR Announced
What happens when you are wearing a virtual reality headset, and have a sudden craving to search for something on Google? Rather than move away ...

Black Friday Brings Grief To The Family Of Walmart Employee, Jdimytai Damour, Who Was Crushed To Death ...
Every year Black Friday brings grief to the family of Walmart worker Jdimytai Damour, 34, who was crushed to death by a mob of wild shoppers ...

Resources last updated: 12/2/2015 6:23:04 AM