• perl 阿里云签名


    [root@sword ~]# cat tl.pl 
    use  LWP::UserAgent;
    use Data::UUID;
    use Data::GUID;
    use HTTP::Date qw(time2iso str2time time2iso time2isoz);  
    use HTTP::Cookies;
    use POSIX;
    use Data::Dumper;
    use JSON qw/encode_json decode_json/;
     
     sub _init{
    my $uuid  = Data::GUID->new->as_string;
    #print "$uuid is $uuid
    ";
    $region=shift;
    $Action=shift;
    use Encode;
    my $SDATE = strftime("%Y-%m-%dT%H:%M:%SZ",localtime());
    use URI::Escape;  
    $SDATE=uri_escape("$SDATE"); 
    #print "$SDATE is $SDATE
    X";
    $SDATEX = $SDATE;
    $SDATEX =~ s#%#%25#g;
    #print "$SDATEX is $SDATEX
    ";
     
     
    use URI::Escape qw(uri_unescape);
    use MIME::Base64;
    use Digest::HMAC_SHA1;
    $xx="GET&%2F&AccessKeyId%3DLTAIb9zHh7U0Us3e%26Action%3D$Action%26Format%3DJSON%26RegionId%3D$region%26SignatureMethod%3DHMAC-SHA1%26SignatureNonce%3D$uuid%26SignatureVersion%3D1.0%26TimeStamp%3D$SDATEX%26Version%3D2014-05-26";
    $xx = encode_utf8($xx);
    #print "$xx is $xx
    ";
    $str=Digest::HMAC_SHA1::hmac_sha1("$xx","VbG8qFvhNEfWzilgNh0IAdeqXyhua2&");
    $Signature = encode_base64($str,"");
    #print "$Signature
    ";
    $Signature = encode_utf8($Signature);
    print "$Signature
    ";
     
     
    $head='http://ecs.aliyuncs.com/?';
    #+ ͦۻΪ%20 =ͦۻΪ%3d
    $Signature = uri_escape("$Signature");
     
    $api="SignatureVersion=1.0&Format=JSON&TimeStamp=$SDATE&RegionId=$region&AccessKeyId=LTAIb9zHh7U0Us3e&SignatureMethod=HMAC-SHA1&Version=2014-05-26&Signature=$Signature&Action=$Action&SignatureNonce=$uuid";
    $url=$head.$api;
    #print "$url is $url
    ";
    };
     
    sub get_url{
    $url=shift;
    $ua = LWP::UserAgent->new;
    $ua->timeout(10);
    $ua->env_proxy;
    $ua->agent("Mozilla/8.0");
    my $cookie_jar = HTTP::Cookies->new(
        file           => 'lwp_cookies.txt',
        autosave       => 1,
        ignore_discard => 1
    );
    $ua->cookie_jar($cookie_jar);
     
    #
    #
    print $url."
    ";
    my $response = $ua->get($url);
     
     
    if ($response->is_success) {
    $yy=$response->decoded_content;
    # print $yy;  # or whatever
      }
      else {
    #     print $response->decoded_content;  # or whatever
            die $response->status_line;
               }
               };
    &_init(region1,DescribeRegions);
    &get_url($url);
     
    &_init('cn-hangzhou',DescribeInstances);
    &get_url($url);
    my $d= $yy;
    $d = decode_json($d);
    $xx=$d->{Instances}->{Instance}
    ;
    foreach (@{$xx}) {
    print "InstanceID is $_->{InstanceId}
    ";
    print "ExpiredTime is $_->{ExpiredTime}
    ";
    print "IPaddr is $_->{PublicIpAddress}->{IpAddress}->[0]
    "};
    [root@sword ~]# 
    [root@sword ~]# perl tl.pl 
    7FBJCysa6JTGGohHJVrFkrFT0EM=
    http://ecs.aliyuncs.com/?SignatureVersion=1.0&Format=JSON&TimeStamp=2018-12-13T11%3A14%3A31Z&RegionId=region1&AccessKeyId=LTAIb9zHh7U0Us3e&SignatureMethod=HMAC-SHA1&Version=2014-05-26&Signature=7FBJCysa6JTGGohHJVrFkrFT0EM%3D&Action=DescribeRegions&SignatureNonce=43B30DEA-FEC8-11E8-B7C7-F3D4E4AD0724
    2MWV+x0r7Bb08Kmabtekxlr7Ctg=
    http://ecs.aliyuncs.com/?SignatureVersion=1.0&Format=JSON&TimeStamp=2018-12-13T11%3A14%3A31Z&RegionId=cn-hangzhou&AccessKeyId=LTAIb9zHh7U0Us3e&SignatureMethod=HMAC-SHA1&Version=2014-05-26&Signature=2MWV%2Bx0r7Bb08Kmabtekxlr7Ctg%3D&Action=DescribeInstances&SignatureNonce=43C76ACE-FEC8-11E8-B7C7-F3D4E4AD0724
    InstanceID is i-bp19navp6ed70a4ihwsx
    ExpiredTime is 2021-10-18T16:00Z
    IPaddr is 47.99.174.88
  • 相关阅读:
    (十一)QPainter绘图, QPixmap,QImage,QPicture,QBitmap
    (十)事件,定时器
    (九)自定义控件
    (八)控件介绍,QLable
    (六)QDialog,QMessageBox,QFileDialog,QColorDialog颜色,QFontDialog字体
    (七)布局
    (五)qt资源文件
    (四)窗口mainwindow
    (三)信号与槽
    JMeter学习-011-JMeter 后置处理器实例之
  • 原文地址:https://www.cnblogs.com/hzcya1995/p/13348934.html
Copyright © 2020-2023  润新知