Skip to content

Instantly share code, notes, and snippets.

@iOS0x00
Last active August 30, 2015 12:14
Show Gist options
  • Save iOS0x00/3379015fd0c4059a3f35 to your computer and use it in GitHub Desktop.
Save iOS0x00/3379015fd0c4059a3f35 to your computer and use it in GitHub Desktop.
阿里云ECS获取所有vps的IP sample
# -*- 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