Skip to content

Instantly share code, notes, and snippets.

@bssanchez
Created September 26, 2017 18:48
Show Gist options
  • Select an option

  • Save bssanchez/e57cacbcd183f8c09795ac988152bb30 to your computer and use it in GitHub Desktop.

Select an option

Save bssanchez/e57cacbcd183f8c09795ac988152bb30 to your computer and use it in GitHub Desktop.
Perl script for consulting webpages by multiple HTTP methods
#!/bin/perl
use warnings;
use strict;
use LWP::UserAgent;
use HTTP::Request;
my $lol = 0;
my $mtd = 0;
my $menu = 0;
my $url = "";
my $peti;
my $resp;
sub menu
{
if($menu == 0)
{
print "Metodo de peticion disponibles: ";
print "\n [1] GET";
print "\n [2] POST";
print "\n [3] PUT";
print "\nElije [1-3]: ";
$menu = 1;
}
$mtd = <STDIN>;
if(!($mtd =~ /[1-3]/))
{
print "[X] Error, debes elegir un numero de 1 a 3: ";
&menu;
}
}
sub url
{
print "URL: ";
$url = <STDIN>;
if(!($url =~ /^http:\/\//))
{
$url = "http://".$url;
}
}
sub type
{
if($mtd == 1)
{
$peti = HTTP::Request->new(GET => $url);
}
elsif($mtd == 2)
{
$peti = HTTP::Request->new(POST => $url);
}
else
{
$peti = HTTP::Request->new(PUT => $url);
}
}
sub conexion
{
print "\nEstableciendo conexion";
my $nav = LWP::UserAgent->new();
$nav->agent("Lolz 2.0.1 - Linux RedHat v1000");
chomp $url;
&type;
$resp = $nav->request($peti);
$resp = $resp->content();
print "\nRespuesta desde servidor: [[$url]]";
#print "\n\n".$resp;
$lol = 1;
}
sub archivo
{
if($lol == 1)
{
print "\n\nEscribiendo datos en archivo...";
open(FILE, ">archivo");
print FILE $resp;
close FILE;
print "\n-_Fin_-";
}
}
&menu;
sleep(1);
&url;&conexion;&archivo;
print "\nBy kid_goth";
print "\n";
sleep(3);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment