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; } }
In reply to URL, etc to Domain Name Stripper by jnbek
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |