Daily Archives: 19 April 2016


Automatically download possibly a whole public website using wget recursively

wget -r -k -np --user-agent="Mozilla/5.0 (iPhone; CPU iPhone OS 7_0 like Mac OS X; en-us) AppleWebKit/537.51.1 (KHTML, like Gecko) Version/7.0 Mobile/11A465 Safari/9537.53" --wait=2 --limit-rate=200K --recursive --no-clobber --page-requisites --convert-links --domains bytefreaks.net https://bytefreaks.net/;

Introduction:

The “wget” command is a powerful tool used to download files and web pages from the internet. It is commonly used in Linux/Unix environments but can also be used on other operating systems. The command comes with various options and parameters that can be customized to suit your specific download requirements. In this post, we will discuss the wget command with a breakdown of its various options, and how to use it to download files and web pages.

Command Explanation:

Here is a detailed explanation of the options used in the command:

  1. “-r” : This option is used to make the download recursive, which means that it will download the entire website.
  2. “-k” : This option is used to convert the links in the downloaded files so that they point to the local files. This is necessary to ensure that the downloaded files can be viewed offline.
  3. “-np” : This option prevents wget from ascending to the parent directory when downloading. This is helpful when you want to limit the download to a specific directory.
  4. “–user-agent” : This option allows you to specify the user agent string that wget will use to identify itself to the server. In this case, the user agent string is set to a mobile device (iPhone).
  5. “–wait” : This option adds a delay (in seconds) between requests. This is useful to prevent the server from being overloaded with too many requests at once.
  6. “–limit-rate” : This option is used to limit the download speed to a specific rate (in this case, 200K).
  7. “–recursive” : This option is used to make the download recursive, which means that it will download the entire website.
  8. “–no-clobber” : This option prevents wget from overwriting existing files.
  9. “–page-requisites” : This option instructs wget to download all the files needed to display the webpage, including images, CSS, and JavaScript files.
  10. “–convert-links” : This option is used to convert the links in the downloaded files so that they point to the local files. This is necessary to ensure that the downloaded files can be viewed offline.
  11. “–domains” : This option allows you to specify the domain name(s) that you want to download.
  12. https://bytefreaks.net/” : This is the URL of the website that you want to download.

Conclusion:

The wget command is a powerful tool that can be used to download files and web pages from the internet. By using the various options and parameters available, you can customize your download to suit your specific requirements. In this post, we have discussed the wget command and its various options, and how to use it to download files and web pages. We hope that this post has been helpful and informative, and that it has given you a better understanding of the wget command.

Same command without setting the user agent:

The following command will try to download a full website with all pages it can find through public links.

wget --wait=2 --limit-rate=200K --recursive --no-clobber --page-requisites --convert-links --domains example.com http://example.com/;

Parameters:

  • --wait Wait the specified number of seconds between the retrievals.  We use this option to lighten the server load by making the requests less frequent.
  • --limit-rate Limit the download speed to amount bytes per second. We use this option to lighten the server load and to reduce the bandwidth we consume on our own network.
  • --recursive Turn on recursive retrieving.
  • --no-clobber If a file is downloaded more than once in the same directory, we prevent multiple version saving.
  • --page-requisites This option causes Wget to download all the files that are necessary to properly display a given HTML page.
  • --convert-links After the download is complete, convert the links in the document to make them suitable for local viewing.
  • --domains Set domains to be followed.  It accepts a domain-list as a comma-separated list of domains.

PHP: Functions that check passwords if they are strong enough

Following you will find a function that checks a string if it matches certain limitations that are usually applied on passwords.

Specifically, in the following code we check that the input contains at least one small Latin letter, a caps Latin letter, a number and a special character.

//Function that checks if string has at least one small Latin letter, one caps Latin letter, a number and a special character
function validString($string) {
  $containsSmallLetter = preg_match('/[a-z]/', $string);
  $containsCapsLetter = preg_match('/[A-Z]/', $string);
  $containsDigit = preg_match('/\d/', $string);
  $containsSpecial = preg_match('/[^a-zA-Z\d]/', $string);
  return ($containsSmallLetter && containsCapsLetter && $containsDigit && $containsSpecial);
}

In case you do not want to check for the case of the Latin characters and you just want to see if there is any of them we can merge the two checks as follows

//Function that checks if string has at least one Latin letter, a number and a special character
function validString($string) {
  $containsLetter = preg_match('/[a-zA-Z]/', $string);
  $containsDigit = preg_match('/\d/', $string);
  $containsSpecial = preg_match('/[^a-zA-Z\d]/', $string);
  return ($containsLetter && $containsDigit && $containsSpecial);
}

Windows with ffmpeg — recursively convert all *.mov movies to .mp4. with fixed resolution for android 1

We needed to convert a bunch of mov files to mp4 and while doing that we wanted to shrink them down so that they would fit the screen of an older android device.
We did that both to save space on the internal memory and to make the device perform as efficient as possible as it would not have to shrink the video on the fly.

We downloaded the windows binary for ffmpeg from https://ffmpeg.org/ and copied it to the folder we wanted to execute the command from using Windows Explorer.
After that, while holding the Shift key we right clicked in the Windows Explorer empty area to popup the menu. From the menu we selected Open command window here, that opened a Command Prompt that was already navigated in the folder we placed the binary.
To convert the movies we executed the following:

for /R %f in ("*.mov") do (ffmpeg.exe -i "%~f" -s 864x486 -acodec copy "%~pf%~nf.mp4")

What the above command did was, direct command prompt to find recursively all the files that their name ends in .mov (this is the part that looks like this for /R %f in ("*.mov")) and then execute for each a command, in our case was to convert the file to mp4, resize the video while preserving the audio as is and produce a new file that has the same name but different file extension so that new files will have the mp4 extension instead of mov.