-
Notifications
You must be signed in to change notification settings - Fork 1
/
sbing.p6
34 lines (34 loc) · 1.6 KB
/
sbing.p6
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
use lib 'lib';
use Bing;
use JSON::Fast;
use URI;
use Net::DNS;
multi sub MAIN (
:$search , #= Querey Bing.com for urls - takes no value
Str:D :$keyword! , #= Keyword to use as a Querey - required with --search
Int:D :$pages = 10 , #= Number of pages to proccess - optional defaults to 10
Str :$out = 'output' , #= Output file name - optional defaults to output .txt/.json
Bool :$json = False , #= Pass this param to add a 'output.json' with results
Bool :$info = False , #= Get urls info (domain,ip address,path,params) if found any will write json file
) {
my $b = Bing.new(keyword => $keyword , pages => $pages );
my %out = $b.search;
my $out-file = $out.split( '.' )[0];
if $info {
for %out{'urls'}.keys -> $url {
my $uri = URI.new($url);
my $resolver = Net::DNS.new('8.8.8.8');
my $ip = ~$resolver.lookup-ips($uri.host, :inet);
my $cname = ~$resolver.lookup( 'CNAME' , $uri.host);
%out{'hosts'}{$uri.host}{'ips'} = [];
%out{'hosts'}{$uri.host}{'ips'}.push: $ip;
%out{'hosts'}{$uri.host}{'ips'} = %out{'hosts'}{$uri.host}{'ips'}.unique;
%out{'hosts'}{$uri.host}{'CNAME'} = $cname if $cname;
%out{'hosts'}{$uri.host}{'paths'}{$uri.path} = Hash.new;
%out{'hosts'}{$uri.host}{'paths'}{$uri.path}{'params'}.append($uri.query-form.keys) if $uri.query;
}
($out-file ~ '.json').IO.spurt( to-json %out);
} else {
$json ?? ($out-file ~ '.json').IO.spurt( to-json %out) !! ($out-file ~ '.txt').IO.spurt(%out{'urls'}.keys.join("\n")) ;
}
}