Beefy Boxes and Bandwidth Generously Provided by pair Networks
Your skill will accomplish
what the force of many cannot
 
PerlMonks  

Network Outlet

by fluticasone (Initiate)
on Apr 27, 2012 at 15:48 UTC ( #967672=CUFP: print w/ replies, xml ) Need Help??

Mr. fliticasone

Cool uses for Perl, I added two routers to my network, one to act as a gate, two to act as computer during the day and router or gate at night. Because I could not find code to make this router invisible to catch logins ONLY at night. I used a schedule sort of like a slave of the main router close to the modem T1 power up. I feel that I'm being "swiss army knife", becuase I could not stop trojans with NORTON'S Greatest.
#!/usr/bin/perl # checkportopening.pl use strict; use LWP::Simple; use URI::Escape; # MEncoder location my $mencoder = "c:\\mplayer\mencoder.exe"; # Get the Port URL print "paste in a URL and Press Enter. \n% "; my $url = <STDIN>; # Scrape the page my $response = get($url); # find the video file While ($response =~ m!videoURL\u003d(.*?)\\"!gis) { my $videoURL = $1; $videoURL = uri_unescape($videoURL); $videoURl =~ s!\\u003d!=!gs; # Find the site filename my $head = head($videoURL); my $filename = $head->{_headers}->{'content-disposition'}; $filename =~ s!attachment; filename||gis; # Download the video file print "Downloading $filename...\n"; getstore($videoURL,$filename); # make sure downloaded file is there if (-e $filename) { # change the extension my $newfilename = $filename; $newfilename =~ s!flv!avi!gis; print "Converting to $newfilename...\n"; # use MEncoder to convert to another file (rename intruder's site) my $cmd = "$mencoder $filename -ofps 15";

Comment on Network Outlet
Download Code
Re: Network Outlet
by jwkrahn (Monsignor) on Apr 28, 2012 at 03:21 UTC
    #!/usr/bin/perl # checkportopening.pl use strict; use LWP::Simple; use URI::Escape;

    You should also have the warnings pragma in there somewhere.



    # MEncoder location my $mencoder = "c:\\mplayer\mencoder.exe";

    Interpolation will convert that string to: c:\mplayermencoder.exe



    # Get the Port URL print "paste in a URL and Press Enter. \n% "; my $url = <STDIN>; # Scrape the page my $response = get($url);

    You will probably need to chomp that $url variable before you use it.



    # find the video file While ($response =~ m!videoURL\u003d(.*?)\\"!gis) { my $videoURL = $1; $videoURL = uri_unescape($videoURL); $videoURl =~ s!\\u003d!=!gs; # Find the site filename

    You should probably put a } character somewhere at the end of that loop and the word 'While' is not valid Perl.



    # make sure downloaded file is there if (-e $filename) { # change the extension my $newfilename = $filename; $newfilename =~ s!flv!avi!gis; print "Converting to $newfilename...\n"; # use MEncoder to convert to another file (rename intruder's site)

    You should probably put a } character somewhere at the end of that block.

Re: Network Outlet
by Khen1950fx (Canon) on Apr 29, 2012 at 03:12 UTC
    I encountered problems with URI::Escape, so I reworked your script to make it a little simpler. I used LWP::UserAgent instead of LWP::Simple and used ":content_file => " to make a file.
    #!/usr/bin/perl use strict; use warnings; use LWP::UserAgent; use URI::Escape; print "Enter an URL and Press Enter: \n"; my $url = <ARGV>; my $ua = LWP::UserAgent->new; my $response = $ua->get( $url, ':content_file' => '/root/Desktop/url.log', ); die "Couldn't get $url" unless defined $response; if ($response->is_success) { print $response->decoded_content; } else { die $response->status_line; } my $videoURL = uri_escape_utf8($url); my $new_videoURL = uri_unescape($videoURL); print $new_videoURL ;
    This is only a skeleton, but I think that you could usefully build upon it.

    Updated: Revised. Thanks to jwkrahn for catching the mistake.

      my $url = <ARGV>;

      Why change STDIN to ARGV?    And either way you still have to chomp the value received.

      while ($new_videoURL) { chomp; print $new_videoURL ; }

      Does $new_videoURL assign a value to $_?    And if not then why are you chomping the $_ variable?    And if the value in $new_videoURL doesn't change inside the loop then why are you using a loop at all?

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: CUFP [id://967672]
Approved by herveus
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others pondering the Monastery: (18)
As of 2014-09-18 14:13 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    How do you remember the number of days in each month?











    Results (116 votes), past polls