-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathperl-downloader.pl
73 lines (50 loc) · 1.23 KB
/
perl-downloader.pl
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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
#!/usr/bin/perl
print "##############################\n";
print "# PERL Downloader - R&D ICWR #\n";
print "##############################\n";
print "\n";
use LWP::UserAgent;
use Getopt::Long;
GetOptions(
'url=s' => \my $url,
'file=s' => \my $file
);
package downloader;
sub write_file
{
my $class = shift;
my $self = {
'content' => shift,
'file' => shift
};
{
open my $f, '>', "$self->{file}";
print {$f} $self->{content};
close $f;
}
}
sub get_file
{
my $class = shift;
my $self = {
'url' => shift,
'file' => shift
};
my $url = $self->{url};
my $file = $self->{file};
my $req = LWP::UserAgent->new;
$req->agent('Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:75.0) Gecko/20100101 Firefox/75.0');
my $response = $req->get($url);
if ($response->is_success) {
print "[+] Downloaded : $url\n";
if (write_file downloader($response->content, $file)) {
print "[+] Saving file to : $file\n";
} else {
print "[-] Failed saving file to : $file\n";
}
} else {
print "[-] Failed download : $url\n";
}
bless $self, $class;
}
get_file downloader($url, $file);