Skip to content

Commit 3074043

Browse files
committed
updated
1 parent 0c9c777 commit 3074043

File tree

1 file changed

+63
-53
lines changed

1 file changed

+63
-53
lines changed

bin/stealth.pl

Lines changed: 63 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
use feature qw(say);
1818
use strict;
1919
use open qw(:encoding(utf8));
20-
use vars qw($KNOWN @PATHS $PSL @TLDs $IANA $INFO $EXCLUDE);
20+
use vars qw($KNOWN $KNOWN_URLS @PATHS $PSL @TLDs $IANA $INFO $EXCLUDE);
2121
use warnings;
2222

2323
$| = 1;
@@ -36,8 +36,10 @@
3636
'ml' => 'rdap.nic.ml',
3737
'ke' => 'whois.kenic.or.ke',
3838
'gov' => 'rdap.cloudflareregistry.com',
39+
};
3940

40-
# reported by @notpushkin, see https://gist.github.com/notpushkin/6220d8efa5899dbb0dcff1b9ccf729d4
41+
# reported by @notpushkin, see https://gist.github.com/notpushkin/6220d8efa5899dbb0dcff1b9ccf729d4
42+
$KNOWN_URLS = {
4143
"ac" => "https://rdap.identitydigital.services/rdap/",
4244
"ae" => "https://rdap.nic.ae/", # works but no data
4345
"ag" => "https://rdap.identitydigital.services/rdap/",
@@ -123,56 +125,67 @@ sub check_tld {
123125
my $tld = shift;
124126
say STDERR sprintf('checking .%s...', uc($tld));
125127

126-
#
127-
# this will contain a list of hosts
128-
#
129-
my @hosts;
130-
131-
push(@hosts, $KNOWN->{$tld}) if (exists($KNOWN->{$tld}));
128+
my $domain = [ Data::Tranco->top_domain($tld) ]->[0];
132129

133-
#
134-
# this will be populated with any domain name found
135-
# in the TLD's RDAP record
136-
#
137-
my @domains;
130+
my @urls;
138131

139-
if (!exists($INFO->{$tld})) {
140-
say STDERR sprintf('missing info for .%s!', uc($tld));
141-
return;
142-
}
132+
if (exists($KNOWN_URLS->{$tld})) {
133+
say STDERR sprintf('.%s has a known URL (%s)', uc($tld), $KNOWN_URLS->{$tld});
134+
push(@urls, URI->new($KNOWN_URLS->{$tld}));
143135

144-
my $rdap = $INFO->{$tld};
145-
146-
#
147-
# extract domains from related links
148-
#
149-
foreach my $link (grep { 'related' eq $_->rel } $rdap->links) {
150-
push (@domains, $PSL->get_root_domain($link->href->host));
151-
}
136+
} else {
137+
#
138+
# this will contain a list of hosts
139+
#
140+
my @hosts;
141+
142+
if (exists($KNOWN->{$tld})) {
143+
say STDERR sprintf('.%s has a known RDAP server (%s)', uc($tld), $KNOWN->{$tld});
144+
push(@hosts, $KNOWN->{$tld});
145+
146+
} else {
147+
#
148+
# this will be populated with any domain name found
149+
# in the TLD's RDAP record
150+
#
151+
my @domains;
152+
153+
if (!exists($INFO->{$tld})) {
154+
say STDERR sprintf('missing info for .%s!', uc($tld));
155+
return;
156+
}
152157

153-
#
154-
# extract domains from entity email addresses
155-
#
156-
foreach my $email (map { $_->{address} } map { @{$_->vcard->email_addresses} } $rdap->entities) {
157-
push(@domains, $PSL->get_root_domain(Email::Address::XS->parse($email)->host));
158-
}
158+
my $rdap = $INFO->{$tld};
159159

160-
#
161-
# generate a list of hosts from the list of domains
162-
#
163-
@hosts = uniq(map { 'rdap.'.$_ } (grep { defined } @domains, $tld));
160+
#
161+
# extract domains from related links
162+
#
163+
foreach my $link (grep { 'related' eq $_->rel } $rdap->links) {
164+
push (@domains, $PSL->get_root_domain($link->href->host));
165+
}
164166

165-
push(@hosts, $rdap->port43) if ($rdap->port43);
167+
#
168+
# extract domains from entity email addresses
169+
#
170+
foreach my $email (map { $_->{address} } map { @{$_->vcard->email_addresses} } $rdap->entities) {
171+
push(@domains, $PSL->get_root_domain(Email::Address::XS->parse($email)->host));
172+
}
166173

167-
my ($domain, undef) = Data::Tranco->top_domain($tld);
174+
#
175+
# generate a list of hosts from the list of domains
176+
#
177+
@hosts = uniq(map { 'rdap.'.$_ } (grep { defined } @domains, $tld));
168178

169-
my @paths;
170-
if ($domain) {
171-
@paths = map { $_.'/domain/'.$domain } ('/'.$tld, @PATHS);
179+
push(@hosts, $rdap->port43) if ($rdap->port43);
180+
}
172181

173-
} else {
174-
@paths = map { $_.'/help '} ('/'.$tld, @PATHS);
182+
foreach my $host (map { lc } @hosts) {
183+
foreach my $path (@PATHS) {
184+
$path =~ s/\/+/\//g;
175185

186+
push(@urls, URI->new(q{https://}.$host.$path)->canonical);
187+
}
188+
}
176189
}
177190

178191
my $ua = LWP::UserAgent->new(
@@ -185,20 +198,17 @@ sub check_tld {
185198
}
186199
);
187200

188-
foreach my $host (map { lc } @hosts) {
189-
foreach my $path (@paths) {
190-
$path =~ s/\/+/\//g;
191-
192-
my $url = URI->new(q{https://}.$host.$path)->canonical;
201+
foreach my $url (@urls) {
202+
$url->path_segments(grep { length > 0 } $url->path_segments, $domain ? (q{domain}, $domain) : q{help});
193203

194-
my $result = $ua->request(GET($url, connection => 'close'));
204+
say STDERR sprintf('checking %s...', $url);
205+
my $result = $ua->request(GET($url, connection => 'close'));
195206

196-
if (200 == $result->code && $result->header('content-type') =~ m!^application/(rdap\+|)json!i) {
197-
say STDERR sprintf('%s is an RDAP server!', $host);
198-
say STDOUT $tld;
207+
if (200 == $result->code && $result->header('content-type') =~ /^application\/(rdap\+?)json/i) {
208+
say STDERR sprintf('%s returned an RDAP response!', $url);
209+
say STDOUT $tld;
199210

200-
return;
201-
}
211+
return;
202212
}
203213
}
204214
}

0 commit comments

Comments
 (0)