Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revision Previous revision
Next revision
Previous revision
fuss:perl [2015/02/03 00:16]
office [Generate DSA Password]
fuss:perl [2017/02/22 18:30] (current)
Line 1: Line 1:
 +====== Count Characters in String ======
 +
 +Count occurences of the letters ''​p''​ and ''​q''​ in a string ''​$str'':​
 +
 +<code perl>
 +my $pq_count = $str =~ tr/pq//;
 +</​code>​
 +
 +====== Remove Newline From Array ======
 +
 +<code perl>
 +pop @data if $data[-1] eq "​\n";​
 +</​code>​
 +
 +====== Generate DSA Password ======
 +
 +The following is a quick script that generates DSA passwords from an input string. To use, save the script as an executable file, and then issue:
 +
 +<code bash>
 +./dsagen.pl password
 +</​code>​
 +
 +where ''​password''​ is a password you want to hash.
 +
 +
 +<file perl dsagen.pl>​
 +#​!/​usr/​bin/​perl -w
 +###########################################################################​
 +##  Copyright (C) Wizardry and Steamworks 2014 - License: GNU GPLv3      ##
 +###########################################################################​
 +use strict;
 +use Crypt::​PasswdMD5;​
 +
 +if ($#ARGV+1 != 1) {
 +    print "​\nUsage:​ dsagen.pl <​password>​\n";​
 +    exit;
 +}
 +
 +print crypt(
 +    $ARGV[0], ​
 +    sub {
 +        my @table = ( '​.',​ '/',​ 0 .. 9, '​A'​ .. '​Z',​ '​a'​ .. '​z'​ );
 +        my $salt;
 +        for(1..2) {
 +            $salt .= (@table)[rand @table];
 +        }
 +        return $salt;
 +    }
 +)."​\n";​
 +
 +</​file>​
 +====== Calculate IP Address Blocks Given a Range of IP Addresses ======
 +
 +As a one-liner:
 +
 +<code perl>
 +perl -MNet::IP -e '$ip = new Net::IP ("​$ARGV[0] - $ARGV[1]"​);​ print map { "​$_\n"​ } $ip->​find_prefixes();'​ "​127.0.0.1"​ "​127.0.0.2"​
 +</​code>​
 +
 +the script:
 +  * uses the ''​Net::​IP''​ package.
 +  * takes the range of the first argument (''​127.0.0.1''​) and the second argument (''​127.0.0.2''​) passed on the command-line.
 +  * prints the address blocks within that range.
 +
 +An example usage is the following:
 +<code bash>
 +perl -MNet::IP -e '$ip = new Net::IP ("​$ARGV[0] - $ARGV[1]"​);​ print map { "​$_\n"​ } $ip->​find_prefixes();'​ "​127.0.0.0"​ "​127.0.63.255
 +</​code>​
 +
 +which returns:
 +<​code>​
 +127.0.0.0/​18
 +</​code>​
 +
 +====== Set Scheduling Priority ======
 +
 +This can be performed in the following way for the process and the IO priority:
 +
 +<code perl>
 +use BSD::​Resource qw(PRIO_PROCESS setpriority);​
 +use Linux::​IO_Prio qw(IOPRIO_WHO_PROCESS IOPRIO_PRIO_VALUE IOPRIO_CLASS_BE ioprio_set);​
 +BEGIN { 
 +  require autodie::​hints; ​
 +  autodie::​hints->​set_hints_for(
 +    \&​ioprio_set, ​
 +    { 
 +      fail => sub { 
 +        $_[0] == -1 
 +      } 
 +    } 
 +  ) 
 +};
 +use autodie qw(:all setpriority ioprio_set);​
 +
 +setpriority(
 +    PRIO_PROCESS,​
 +    $$,
 +    19 # nice: from -20 most favourable to 19 least favourable ​
 +);
 +ioprio_set(
 +    IOPRIO_WHO_PROCESS,​
 +    $$,
 +    # IOPRIO_CLASS_BE - best effort (0 is most favourable and 7 is least favourable)
 +    IOPRIO_PRIO_VALUE(IOPRIO_CLASS_BE,​ 7)
 +);
 +</​code>​
 +
 +====== Randomise Lines in Text File ======
 +
 +The following one-liner:
 +<code bash>
 +cat lines.txt | perl -MList::​Util -e 'print List::​Util::​shuffle <>'​
 +</​code>​
 +
 +will randomly shuffle the lines in ''​lines.txt''​.
  

fuss/perl.txt ยท Last modified: 2017/02/22 18:30 (external edit)

Access website using Tor Access website using i2p


For the copyright, license, warranty and privacy terms for the usage of this website please see the license, privacy and plagiarism pages.