#!/usr/bin/perl
# "Verisign Typosquatter Explorer" 	Version 1.0
# Seth Finkelstein   sethf[at]sethf.com  http://sethf.com  September 16 2003
# Given URLs as arguments, find Verisign suggested sites
# Format is the URL, then comma-separated lists of sites on different settings
# URL|sites-nofilter|sites-moderate|sites-strict

use LWP::UserAgent;
use HTTP::Request::Common qw(GET);
use HTTP::Cookies;
use strict;

my $UA = new LWP::UserAgent; 

foreach my $url (@ARGV) {
    print $url,'|';
    print join(',',@{get_verisign_squats($url, 'nofilter')}),'|';
    print join(',',@{get_verisign_squats($url, 'moderate')}),'|';
    print join(',',@{get_verisign_squats($url, 'strict')}),"\n";
}

sub get_verisign_squats { # get verisign typo-squats, return an array reference
    my ($nohttp, $supress) = @_; # url minus http, content-control setting
    $nohttp =~ s,^http://,,i;
    my ($host) = $nohttp =~ m,^([^/]+),;

    my $res = $UA->request # this is the page Verisign generates for a typo
	(GET "http://sitefinder.verisign.com/lpc?url=$nohttp&host=$host", 
	 "Cookie" => "PREF=$supress");
# PREF can be 'nofilter', 'moderate', 'strict', controls "offensiveness"

    my @verisign_squats = $res->is_success ? # parse out hosts in page
	sort($res->content =~ m/onMouseOver=\"self.status='(.*?)'/g) :
	("ERROR"); # default in case the connection fails

    return \@verisign_squats; # reference to array of typo-squat suggestions
}
