Perl脚本发送带附件的邮件脚本安全

2024-09-27 其他范文 下载本文

Perl脚本发送带附件的邮件脚本安全(锦集4篇)由网友“岭南ZZ”投稿提供,下面是小编整理过的Perl脚本发送带附件的邮件脚本安全,欢迎您阅读,希望对您有所帮助。

篇1:Perl脚本发送带附件的邮件脚本安全

#!/usr/bin/perl

use strict;

use warnings;

use Net::SMTP;

use MIME::Lite;

use Term::ReadKey;

use Encode qw/decode encode/;

print “From : ”;

chomp(my $from = );

my $server;

#这里我只用到了163和qq的SMTP服务器,。。

$server = “smtp.163.com” if $from =~ /\\@163\\.com/;

$server = “smtp.qq.com” if $from =~ /\\@qq\\.com/;

print “Password : ”;

#输入密码时不显示。。。

ReadMode(“noecho”);

chomp(my $pass = );

ReadMode(“restore”);

print “\\nTo : ”;

chomp(my $to = );

print “Subject : ”;

chomp(my $subject = );

print “Content : \\n”;

chomp(my $content = );

print “Attachment : ”;

chomp(my $file = );

my $smtp = Net::SMTP->new($server, Timeout => 30);

my $msg = MIME::Lite->new(

From=>$from,

To=>$to,

Subject=>$subject,

Type=>“TEXT”,

Data=>$content,

);

if($file) {

#输入流UTF-8编码,视环境的编码而定,

。。

$file = decode(“utf8”, $file);

my $filename = $file;

#输出流转成gbk编码,应对附件的中文乱码问题。。。

$filename = encode(“gbk”, $filename);

#去除路径名,只保留文件名。。。

$filename =~ s/.*\\/|.*\\\\//;

$msg->attach(

Type=>“AUTO”,

Path=>$file,

Filename=>$filename,

);

}

#将邮件全部内容以字符串的形式传递。。。

my $content_string = $msg->as_string or die “$!”;

#使用Net::SMTP发送邮件。。。

$smtp->auth($from, $pass);

$smtp->mail($from);

$smtp->to($to);

$smtp->data();

$smtp->datasend(“$content_string\\n\\n”);

$smtp->dataend();

$smtp->quit;

#如果发送不成功,显示错误信息。。。

unless($smtp->code() == 221) {

print $smtp->message();

}

#发送成功的状态。。。

else {

print “Successfully sent to <$to>!\\n”;

}

#Perl

篇2:Perl文件搜索脚本脚本安全

好久没有写些东西了,。。最近一直在用PERL写一些有趣的程序,几乎每天都有新的程序产生,实在是太有趣了!今天又写了一个用来搜索文件的小程序,虽然我以前也写过类似的,但是方法很繁琐,这次用到了一个很方便的模块:File::Find!代码明显变得简短多了,其中还加了一些自己的想法进去,可以自动修改Windows当中输入的错误,举个简单的例子,比如:程序提示输入一个查找路径,假设输入“C”,程序会自动把它改成“C:”,这样方便查找。还有,在Windows系统中,输入“/”和“\”是都支持的,这样会导致打印出的结果显得很凌乱,如:C:\\\\Perl//searchMyFile.pl,程序都会统一将其改成类似Unix系统中的“/”的形式,如:C:/Perl/searchMyFile.pl。还有很多自动修改的功能,都是用到了PERL强大的正则表达式,不多说了,我把我的代码复制上来,如果大家有兴趣可以帮忙纠正:-)

#!/usr/bin/perl

use strict;

use warnings;

use Cwd;

use File::Find;

####################################################################

File name        : searchMyFile.pl

Written by       : B.S.F

Last modified  : 05/18/

Description      : Easy way to search some file(s) with a keyword!

####################################################################

# Input a path to search...

print “Enter a path: ”;

chomp(my $path = );

# Change “~” or “~/” to your home directory on Linux/FreeBSD platform.

if(($^O eq “linux”) || ($^O eq “freebsd”)) {

$path =~ s/~|~\\//$ENV{'HOME'}/;

}

# Deal with some format of path on Windows NT platform.

else {

# Change “C” to “C:”, etc.

$path .= “:” if $path =~ /^\\w$/;

# Change “C:\\\\” to “C:”, etc.

$path =~ s/\\W+/:/ if $path =~ /^\\w\\W+$/;

# Change “C:\\\\Perl\\” to “C:\\\\Perl”, etc.

$path =~ s/\\W+$// if $path =~ /^\\w\\W+\\w+/;

# Change “C:\\\\Perl” to “C:/Perl”, etc.

$path =~ s/\\W+/:\\// if $path =~ /^\\w\\W+\\w+/;

}

# Test if can enter into the path or not, if not, terminated!

chdir($path) or die “Couldn't get into $path: $!”;

# Input some keyword...

print “Enter a keyword: ”;

chomp(my $key = );

# Change the “.” character to the actually meanings, matching some postfix.

# Such as “.jpg”, “.txt”, “.doc”, etc.

$key =~ s/\\./\\\\./;

# Print some information...

print “Searching under \\”“, getcwd, ”\\“...\\n”;

#

# Searching...

#

sub search {

# Get rid of the directory matches “System Volume Information”(some boring stuff on Windows...).

$File::Find::prune = 1 if /System Volume Information/;

# Open the “i” switch to mach more,  such as “.JPG” or “.jpg”...

if (/$key/i) {

# “” stand for a directory, “” for a file!

my $target = (-d) ? “  $File::Find::name” : “  $File::Find::name”;

# A neat layout for Windows...

$target =~ s/:/:\\// if $target !~ /\\//;

print “$target\\n”;

}

}

# Begin to search...

find(\\&search, $path);

篇3:Codeigniter实现发送带附件的邮件

作者:work24 字体:[增加 减小] 类型:

这篇文章主要介绍了Codeigniter实现发送带附件的邮件的方法,涉及Codeigniter中attach方法的使用技巧,非常具有实用价值,需要的朋友可以参考下

本文实例讲述了Codeigniter实现发送带附件的邮件的方法,分享给大家供大家参考。具体分析如下:

attach 方法允许你的发邮件时带上附件,下面是演示代码

代码如下:

$this->load->library(‘email‘);

$this->email->from(‘w3@w3mentor.com‘, ‘W3M‘);

$this->email->subject(‘Email Test with attachment‘);

$this->email->message(‘Testing the email class IN CODEIGNITER with attachment.‘);

$this->email->attach(‘/path/to/attachment1.jpg‘);

$this->email->send();

希望本文所述对大家基于Codeigniter的php程序设计有所帮助,

篇4:写的一个perl脚本,用于发送远程MySQL命令

想写一些简化管理操作的脚本,下面是基础脚本之一,

对于一个从来没使用过perl脚本的我来说还是有些难度的,直接上代码。

此脚本用于发送远程MySQL命令并且接收结果,功能比较简单,后面会渐渐完善。

#!/usr/bin/perl use Getopt::Long;use DBI; Getopt::Long::GetOptions( ‘host|h=s‘ => \\$host,‘user|u=s‘ => \\$user, ‘password|pw=s‘ => \\$password,‘port|p=s‘ => \\$port,‘command|c=s‘ => \\$command, ‘groupfile|f=s‘ => \\$groupfile, ‘help‘ => \\$help ); #print help info my $printh=q{usage : mysqlcon -h 192.168.0.33 -u root -pw ‘xiaojun‘ -p 3306 -c ‘show global status‘ or mysqlcon -g 2.txt -c ‘select user();‘cat 2.txt:192.168.0.33 root xiaojun 3306192.168.0.34 root xiaojun 3306options:-h database server *-u account name *-pw password for account *-p port for mysqld *-c command to execute *-help print help};=podif(!defined($host)){ print “page flag set to $page ”}if(defined($user)){ print “user flag set to $user\\n ”;}if(defined($password)){ print “onoff flag set to $password \\n”;}if(defined($command)){ print “help flag set to $command \\n”;}if(defined($help)){ print $printh}=cutsub execute_sql{my $dsn = “DBI:mysql:database=mysql;host=$_[0]:$_[1]”;my ($dbh,$sth,@ary);$dbh = DBI->connect($dsn,$_[2],$_[3],{‘RaiseError‘ => 1});$sth = $dbh->prepare(“$_[4]”);$sth->execute(); while(@ary = $sth->fetchrow_array()){print join(“\\t”,@ary),“\\n”;}$sth->finish; $dbh->disconnect; }#&execute_sql($host,$port,$user,$password,$command) ;unless (!defined($help)) { die “$printh” };if(defined($groupfile)){ unless (defined($command)) { die “Wrong usage : No command input .\\n $printh” }; open(IN,$groupfile); while($line=){ my @args=split /\\s/,$line; print “host:@args[0]\\ncommand:$command\\n******BEGIN\\n”; &execute_sql(@args[0],@args[3],@args[1],@args[2],$command) ; print “******END \\n\\n\\n*****************************************************\\n\\n\\n”; }}else{unless (defined($host)) { die “Wrong usage : No host input .\\n $printh” };unless (defined($user)) { die “Wrong usage : No account input .\\n $printh” };unless (defined($password)) { die “Wrong usage : No password input .\\n $printh” };unless (defined($port)) { die “Wrong usage : No port number input .\\n $printh” };unless (defined($command)) { die “Wrong usage : No command input .\\n $printh” };&execute_sql($host,$port,$user,$password,$command) ;}

使用方法

[root@centos511 ~]# ./6.perl -h 192.168.0.33 -u root -pw ‘xiaojun‘ -p 3306 -c ‘select user()‘ ;root@192.168.0.33[root@centos511 ~]# ./6.perl -g 2.txt -c ‘select user()‘ host:192.168.0.33command:select user()******BEGINroot@192.168.0.33******END *****************************************************host:192.168.0.33command:select user()******BEGINroot@192.168.0.33******END *****************************************************[root@centos511 ~]# cat 2.txt 192.168.0.33 root xiaojun 3306192.168.0.33 root xiaojun 3306[root@centos511 ~]# ./6.perl -helpusage : mysqlcon -h 192.168.0.33 -u root -pw ‘xiaojun‘ -p 3306 -c ‘show global status‘ or mysqlcon -g 2.txt -c ‘select user();‘cat 2.txt:192.168.0.33 root xiaojun 3306192.168.0.34 root xiaojun 3306options:-h database server *-u account name *-pw password for account *-p port for mysqld *-c command to execute *-help print help

《Perl脚本发送带附件的邮件脚本安全.docx》
将本文的Word文档下载,方便收藏和打印
推荐度:
Perl脚本发送带附件的邮件脚本安全
点击下载文档
相关专题
[其他范文]相关推荐
    [其他范文]热门文章
      下载全文