• perl 获取阿里云主机信息


    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%3DZ7bph8ZgNR4oMNVh%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","xxxx;
    $Signature = encode_base64($str,"");
    #print "$Signature
    ";
    $Signature = encode_utf8($Signature);
     
    
    $head='http://ecs.aliyuncs.com/?';
    #+ ͦۻΪ%20 =ͦۻΪ%3d
    $Signature = uri_escape("$Signature");
    
    $api="SignatureVersion=1.0&Format=JSON&TimeStamp=$SDATE&RegionId=$region&AccessKeyId=Z7bph8ZgNR4oMNVh&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);
    
    #
    #
    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]
    "};
    

  • 相关阅读:
    YII框架学习(二)
    YII框架学习(一)
    valid number 判断字符串是否为有效数字
    leetcode Add Binary
    leetcode Minimum Path Sum
    leetcode Unique Paths II
    leetcode[61] Unique Paths
    leetcode[60] Rotate List
    leetcode Permutation Sequence
    leetcode Spiral Matrix II
  • 原文地址:https://www.cnblogs.com/hzcya1995/p/13351006.html
Copyright © 2020-2023  润新知