📜 ⬆️ ⬇️

Download from Rapidshare to the console and automatically reset the PPP session

Hi Habrayuzer!

Wrote scripts to reset PPPOE session on ADSL modem via PC
Inspired me to write scripts HERE THIS TOPIC.
Since I do not have a white IP address, I use them to reconnect the session.
This allows me to download from file hosting without delay and waiting.

Scripts written for Linux OS
Program required - expect
Changing the IP address takes ~ 20 seconds .
It was tested on the StarNet ADSL modem pereshito in Acorp Lan 120
Well, of course, you will need telnet or ssh access to your ADSL modem.
')
Idea :

When the ppp0 connection is disconnected , the next file from the list is automatically reconnected and downloaded.
I just run this script on the server and during the night it downloads everything I need.
Only 3 scripts, all folded in one folder.

p1 - Finds the PID of the PPPD daemon

P1 script listing:
#!/usr/bin/expect -f
log_user 0
spawn telnet 192.168.1.1
expect "BusyBox on router login:" {send "root\r"}
expect "Password:" {send "Admin\r"}
expect "#" {send "ps ax |grep pppd\r"}
log_user 1
send "exit\r"
expect eof


p2 - Kills PPPD by PID
And the modem IMMEDIATELY automatically lifts up again.

Listing p2 script:
#!/usr/bin/expect -f
set pid [lindex $argv 0]
log_user 0
spawn telnet 192.168.1.1
expect "BusyBox on router login:" {send "root\r"}
expect "Password:" {send "Admin\r"}
expect "#" {send "kill $pid"}
send "exit\r"
expect eof

Correct the IP modem on your own.

We also need the DownloadFromRS script.
It is intended for downloading files from Rapida through the console, using wget.

Now we need to edit the DownloadFromRS script.
so that after the end of the download, he would perform a script to reset the PPP session.

Listing Modified Script:
#!/bin/bash

################################################
#Purpose: Automate the downloading of files from rapidshare using the free account
#using simple unix tools.
#Date: 14-7-2008
#Authors: Slith, Tune
#Improvements: Please email them to jwhatson@gmail.com
#Post Feedback and comments to emkay.unpointless.com/Blog/?p=63
#Notes: To use curl instead of wget use 'curl -s' and 'curl -s -d'
#Version: 1.2 - Rapidshare has added a wait time in between file downloads. On top of your download
#to start. This has been fixed.
#Added a 'kill time' feature. Specify killTime as an hour of the day and if the time is greater than this.
#the script will end. Useful for using cron to start script at offpeak time and killing it when off speak ends.
################################################

mirror=dt.rapidshare.com;

## possible mirrors
# cg.rapidshare.com
# l34.rapidshare.com
# tg.rapidshare.com
# gc2.rapidshare.com
# dt.rapidshare.com
# tl2.rapidshare.com
# l32.rapidshare.com
# l3.rapidshare.com
# gc.rapidshare.com
# l33.rapidshare.com
# tl.rapidshare.com
# cg2.rapidshare.com

killTimeEnable=0
killTime=9

function getOutputFromFreeUserSubmit(){
URL=$(wget -q -O - $line | grep "<form id=\"ff\" action=\"" | grep -o 'http://[^"]*');
output=$(wget -q -O - --post-data "dl.start=Free" "$URL");
}

while read line
do

if [[ $killTimeEnable -eq 1 && $(date +%H) -gt $killTime ]]; then exit; fi;

getOutputFromFreeUserSubmit output; #call getOutputFromFreeUserSubmit, result is stored in $output
posibleWaitTime=$(echo "$output" | grep "try again in about" | grep -o "[0-9]\{1,3\}");

if [ -z "$posibleWaitTime" ]; then #check for zero lenght string
echo "No wait time, likely to be the first file you have downloaded in a while";
else
echo "Waiting $[ $posibleWaitTime+1] minutes (in between file download wait)";
sleep $[ $posibleWaitTime+1]m;
getOutputFromFreeUserSubmit output; #Now we have waited we will try again...
fi

time=$(echo "$output" | grep "var c=[0-9]*;" | grep -o "[0-9]\{1,3\}");
ourfile=$(echo "$output" | grep "document.dlf.action=" | grep -o "http://[^\"]*$mirror[^\\]*");
echo "Waiting $time secs for download of $ourfile";
sleep $time;
wget $ourfile;
./p1 | grep pppd | grep -v grep | awk '{print $1;}' | xargs ./p2;
sleep 5;

done < input.txt

It remains to make the file executable , drop the necessary links into the file input.txt and start the download.
All scripts must be in the same folder.
Everything is very simple and effective.

Ps . It is also possible to break the VPN connection, etc.
Dynamic IP is cool!

Download all the scripts in one archive can be HERE
You can also view them with syntax highlighting in my BLOG .

Source: https://habr.com/ru/post/60720/


All Articles