This is my first Perl script used for daily work,record and make some explanation here.
[code]
#!/usr/bin/perl
use strict;
use warnings;
use Getopt::Long;
if ($#ARGV > 0 || $#ARGV < 0 || $ARGV[0] !~ /^[0-9]+$/) {
print "\nUsage:\tOnly 1 numberic argument is ok.\n\n";
exit;
}
sub GetRandNum() {
my $lower=33;
my $upper=126;
my $random = int(rand( $upper-$lower+1 )) + $lower;
return $random;
}
my $pwdlen=$ARGV[0];
my $count=0;
my $password="";
while ($count < $pwdlen) {
my $num=GetRandNum();
$password=$password.chr($num);
$count ++;
}
print "$password\n";
[/code]
Since this script is very simple,I won’t comment in it. Just list some points:
- The script is used to generate radon password which contains lower/upper/special characters or numbers,which should be more secure.
- Function int(),rand(),chr() are used to get integer,radon values and keyboard characters.
- Loop while is used to get radon character one by one,until length is up to limited.
- #$ARGV is the number of arguments given by user,$ARGV[0] is the first argument.
Some output paste here:
[user@host perl]$./test1.pl
Usage: Only 1 numberic argument is ok.
[user@host perl]$./test1.pl 8
jMe=aoM(
[user@host perl]$./test1.pl 8 9
Usage: Only 1 numberic argument is ok.
[user@host perl]$./test1.pl a
Usage: Only 1 numberic argument is ok.
Usage: Only 1 numberic argument is ok.
[user@host perl]$./test1.pl 8
jMe=aoM(
[user@host perl]$./test1.pl 8 9
Usage: Only 1 numberic argument is ok.
[user@host perl]$./test1.pl a
Usage: Only 1 numberic argument is ok.
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。