Last active
August 30, 2015 12:14
-
-
Save iOS0x00/3379015fd0c4059a3f35 to your computer and use it in GitHub Desktop.
阿里云ECS获取所有vps的IP sample
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# -*- coding: utf-8 -*- | |
import aliyun.api | |
import sys | |
aliyun.setDefaultAppInfo("key", "secret") | |
a = aliyun.api.Ecs20140526DescribeInstancesRequest() | |
def get_instance_ip(region=''): | |
a.RegionId = region | |
a.PageSize = 50 | |
try: | |
data = a.getResponse() | |
except Exception, e: | |
print(e) | |
sys.exit(1) | |
# from pprint import pprint | |
# pprint(data) | |
instance = data['Instances']['Instance'] | |
struct = {} | |
for i in instance: | |
hostname = i['HostName'] | |
name = i['InstanceName'] | |
ipaddress = i['PublicIpAddress']['IpAddress'][0] | |
status = i['Status'] | |
struct[ipaddress] = [hostname, name, status] | |
return struct | |
if __name__ == '__main__': | |
ip_pools = [] | |
for region in ['cn-shenzhen', 'cn-hangzhou']: | |
ip_pools.extend(get_instance_ip(region).keys()) | |
print ip_pools | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment