My domain name stripper. Takes a Full URL with GET variables, an email address, www.domain.com domain.com address and spits out either fqdn.domain.com or domain.com for use when running under taint mode, depending on the type requested.
Note: This only works for single dot TLDs (.com, .net, .info, .ca, etc) and not intl TLDs like .co.uk etc with multiple dots.$self->stripper('fqdn', $url); # www.domain.com $self->stripper('regdn', $url); #domain.com
sub stripper { my $type = shift; my $url = shift; if ( $url =~ m/((?:(?:https?|ftp|irc):\/\/|(?:(?:(www)|(ftp))[\w-]*\.))?[-\w\/~\@:] ++\.\S+[\w\/])/i ) { $url = "$1"; } else { &err($url); } $url =~ s/^https?:\/\/|mailto:|(.*)\@//ig ; # get http(s)://, mailto:, and email@ $url =~ s/\/.*//; #Strip out the / and everything aft +er it $url =~ s/[\?\#\:].*//; # Get any GET vars my $fqdn = $url; my @domain = split( /\./, $url ); # We have to do this backwards (com.domain.sub) my $tld = pop(@domain); #.com my $secld = pop(@domain); #.domain my @result = ( $secld, $tld ); my $regdn = join( "\.", @result ); if ( $type eq "fqdn" ) { return $fqdn; } else { return $regdn; } }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: URL, etc to Domain Name Stripper
by ikegami (Patriarch) on Dec 30, 2009 at 22:12 UTC | |
|
Re: URL, etc to Domain Name Stripper
by MidLifeXis (Monsignor) on Dec 30, 2009 at 22:20 UTC | |
|
Re: URL, etc to Domain Name Stripper
by MidLifeXis (Monsignor) on Dec 30, 2009 at 21:32 UTC | |
by jnbek (Scribe) on Dec 30, 2009 at 22:04 UTC | |
by ikegami (Patriarch) on Dec 30, 2009 at 22:27 UTC | |
|
Re: URL, etc to Domain Name Stripper
by jnbek (Scribe) on Dec 31, 2009 at 17:22 UTC |