write down,forget
标签 Tag : Perl

域名批量查询脚本,附词典

<Category: Perl, 乱搞, 小道消息> Comments Off on 域名批量查询脚本,附词典

whois domain query tool

批量whois查询域名是否被注册的perl脚本,支持词典,支持任何后缀的域名,原理很简单,调用whois命令,比较返回结果。windows(cygwin)、linux测试通过。
使用方法: perl domain.pl ‘.com’ ‘domain(3).dict’ #第一个参数为域名后缀,第二个为字典路径,两个参数都为必填哦。
阅读这篇文章的其余部分 »

本文来自: 域名批量查询脚本,附词典

nginx下fastcgi方式运行Perl程序

<Category: Linux> Comments Off on nginx下fastcgi方式运行Perl程序

见鬼了,这篇文章又丢失了,vps的数据难道回滚了,靠。
perl
1.安装FCGI:

2.安装FCGI-ProcManager

3.编辑两个文件

cd /usr/local/nginx/
  ls
  cd sbin/
  ls
  vi cgiwrap-fcgi.pl
  chmod +x cgiwrap-fcgi.pl

4.cgiwrap-fcgi.pl文件内容
#!/usr/bin/perl -w
use FCGI;
use Socket;
use FCGI::ProcManager;
sub shutdown { FCGI::CloseSocket($socket); exit; }
sub restart  { FCGI::CloseSocket($socket); &main; }
use sigtrap ‘handler’, &shutdown, ‘normal-signals’;
use sigtrap ‘handler’, &restart,  ‘HUP’;
require ‘syscall.ph’;
use POSIX qw(setsid);
 
#&daemonize; we don’t daemonize when running under runsv
#this keeps the program alive or something after exec’ing perl scripts
END()   { }
BEGIN() { }
{
    no warnings;
    *CORE::GLOBAL::exit = sub { die “fakeexitnrc=” . shift() . n; };
};
eval q{exit};
if ($@) {
    exit unless $@ =~ /^fakeexit/;
}
&main;
 
sub daemonize() {
    chdir ‘/’ or die “Can’t chdir to /: $!”;
    defined( my $pid = fork ) or die “Can’t fork: $!”;
    exit if $pid;
    setsid() or die “Can’t start a new session: $!”;
    umask 0;
}
 
sub main {
 
#$socket = FCGI::OpenSocket( “127.0.0.1:8999”, 10 ); #use IP sockets
#$socket = FCGI::OpenSocket( “/var/run/nginx/perl_cgi-dispatch.sock”, 10 ); #use UNIX sockets – user running this script must have w access to the ‘nginx’ folder!!
#foreach $item (keys %ENV) { delete $ENV{$item}; }
    $proc_manager = FCGI::ProcManager->new( {n_processes => 5} );
    $socket = FCGI::OpenSocket( “/var/run/fcgi.sock”, 10 )
        ; #use UNIX sockets – user running this script must have w access to the ‘nginx’ folder!!
    $request =
        FCGI::Request( *STDIN, *STDOUT, *STDERR, %req_params, $socket,
        &FCGI::FAIL_ACCEPT_ON_INTR );
    $proc_manager>pm_manage();
    if ($request) { request_loop() }
    FCGI::CloseSocket($socket);
}
 
sub request_loop {
    while ( $request>Accept() >= 0 ) {
        $proc_manager>pm_pre_dispatch();
 
        #processing any STDIN input from WebServer (for CGI-POST actions)
        $stdin_passthrough = ;
        { no warnings; $req_len = 0 + $req_params{‘CONTENT_LENGTH’}; };
        if ( ( $req_params{‘REQUEST_METHOD’} eq ‘POST’ ) && ( $req_len != 0 ) )
        {
            my $bytes_read = 0;
            while ( $bytes_read < $req_len ) {
                my $data = ;
                my $bytes = read( STDIN, $data, ( $req_len$bytes_read ) );
                last if ( $bytes == 0 || !defined($bytes) );
                $stdin_passthrough .= $data;
                $bytes_read += $bytes;
            }
        }
 
        #running the cgi app
        if (
            ( -x $req_params{SCRIPT_FILENAME} ) &&    #can I execute this?
            ( -s $req_params{SCRIPT_FILENAME} ) &&    #Is this file empty?
            ( -r $req_params{SCRIPT_FILENAME} )       #can I read this file?
            )
        {
            pipe( CHILD_RD,   PARENT_WR );
            pipe( PARENT_ERR, CHILD_ERR );
            my $pid = open( CHILD_O, “-|” );
            unless ( defined($pid) ) {
                print(“Content-type: text/plainrnrn);
                print
“Error: CGI app returned no output – Executing $req_params{SCRIPT_FILENAME} failed !n;
                next;
            }
            $oldfh = select(PARENT_ERR);
            $|     = 1;
            select(CHILD_O);
            $| = 1;
            select($oldfh);
            if ( $pid > 0 ) {
                close(CHILD_RD);
                close(CHILD_ERR);
                print PARENT_WR $stdin_passthrough;
                close(PARENT_WR);
                $rin = $rout = $ein = $eout = ;
                vec( $rin, fileno(CHILD_O),    1 ) = 1;
                vec( $rin, fileno(PARENT_ERR), 1 ) = 1;
                $ein    = $rin;
                $nfound = 0;
 
                while ( $nfound =
                    select( $rout = $rin, undef, $ein = $eout, 10 ) )
                {
                    die “$!” unless $nfound != –1;
                    $r1 = vec( $rout, fileno(PARENT_ERR), 1 ) == 1;
                    $r2 = vec( $rout, fileno(CHILD_O),    1 ) == 1;
                    $e1 = vec( $eout, fileno(PARENT_ERR), 1 ) == 1;
                    $e2 = vec( $eout, fileno(CHILD_O),    1 ) == 1;
 
                    if ($r1) {
                        while ( $bytes = read( PARENT_ERR, $errbytes, 4096 ) ) {
                            print STDERR $errbytes;
                        }
                        if ($!) {
                            $err = $!;
                            die $!;
                            vec( $rin, fileno(PARENT_ERR), 1 ) = 0
                                unless ( $err == EINTR or $err == EAGAIN );
                        }
                    }
                    if ($r2) {
                        while ( $bytes = read( CHILD_O, $s, 4096 ) ) {
                            print $s;
                        }
                        if ( !defined($bytes) ) {
                            $err = $!;
                            die $!;
                            vec( $rin, fileno(CHILD_O), 1 ) = 0
                                unless ( $err == EINTR or $err == EAGAIN );
                        }
                    }
                    last if ( $e1 || $e2 );
                }
                close CHILD_RD;
                close PARENT_ERR;
                waitpid( $pid, 0 );
            } else {
                foreach $key ( keys %req_params ) {
                    $ENV{$key} = $req_params{$key};
                }
 
                # cd to the script’s local directory
                if ( $req_params{SCRIPT_FILENAME} =~ /^(.*)/[^/]+$/ ) {
                    chdir $1;
                }
                close(PARENT_WR);
 
                #close(PARENT_ERR);
                close(STDIN);
                close(STDERR);
 
                #fcntl(CHILD_RD, F_DUPFD, 0);
                syscall( &SYS_dup2, fileno(CHILD_RD)0 );
                syscall( &SYS_dup2, fileno(CHILD_ERR), 2 );
 
                #open(STDIN, “<&CHILD_RD”);
                exec( $req_params{SCRIPT_FILENAME} );
                die(“exec failed”);
            }
        } else {
            print(“Content-type: text/plainrnrn);
            print
“Error: No such CGI app – $req_params{SCRIPT_FILENAME} may not exist or is not executable by this process.n;
        }
    }
}

运行脚本


运行下面的命令来查看perl是否运行

5.添加文件

6.Nginx配置

fascgi_params内容如下:

本文来自: nginx下fastcgi方式运行Perl程序

Centos中安装snmp用监控宝监测VPS

<Category: Linux> Comments Off on Centos中安装snmp用监控宝监测VPS

首先安装snmp
yum install -y net-snmp net-snmp-utils

v3c的验证方式,添加一个只读帐号,如下:rouser jiankongbao auth
上面添加帐号的意思是:在v3c中,“rouser”用于表示只读帐号类型,随后的“jiankongbao”是指定的用户名,后边的“auth”指明需要验证。
接下来需要创建 jiankongbao这个用户,我们需要这个文件:/var/net-snmp/snmpd.conf,这个文件会在snmpd启动的时候被自动调用,由于此时我们还没有运行snmp,所以手动创建这个文件
mkdir /var/net-snmp
touch /var/net-snmp/snmpd.conf
vim /var/net-snmp/snmpd.conf

输入以下文字
createUser jiankongbao MD5 mypassword
这行配置的意思是创建一个名为“jiankongbao”的用户,密码为“mypassword”,并且用MD5进行加密传输。这里要提醒的是,密码至少要有8个字节,这是SNMP协议的规定,如果小于8个字节,通信将无法进行

运行snmp

service snmpd start
设置成开机自动运行
chkconfig snmpd on

完了就可以在监控宝后台添加服务器监控了

本文来自: Centos中安装snmp用监控宝监测VPS

Veritas输出文件处理入库

<Category: Perl> Comments Off on Veritas输出文件处理入库

算是perl一个测验吧,完成对文本的处理,并入库mysql,写的很烂,记录一下,大家不要笑。所有文件打包

阅读这篇文章的其余部分 »

本文来自: Veritas输出文件处理入库