• 阿里云ECS获取信息的相关接口


    一、元数据接口官方文档

    https://help.aliyun.com/document_detail/49122.html?spm=5176.20966629.toubu.3.f2991ddcpxxvD1#title-d20-np3-qf1

    二、常用接口

    1、网卡对应的网络相关

    #获取网卡mac地址
    MAC=`curl -s http://100.100.100.200/latest/meta-data/network/interfaces/macs/
    
    #网卡对应的子网掩码
    curl http://100.100.100.200/latest/meta-data/network/interfaces/macs/${MAC}/netmask
    #网卡主私IP地址
    curl http://100.100.100.200/latest/meta-data/network/interfaces/macs/${MAC}/primary-ip-address
    #网卡的网关地址
    curl http://100.100.100.200/latest/meta-data/network/interfaces/macs/${MAC}/gateway

    2、vpc相关

    #使用的vpc实例id
    curl http://100.100.100.200/latest/meta-data/vpc-id
    #vpc实例的网段
    curl http://100.100.100.200/latest/meta-data/vpc-cidr-block
    #使用的交换机实例id
    curl http://100.100.100.200/latest/meta-data/vswitch-id
    #交换机网段
    curl http://100.100.100.200/latest/meta-data/vpc-cidr-block

    3、ecs实例相关

    #实例规格
    curl http://100.100.100.200/latest/meta-data/instance/instance-type
    #实例创建时间(+8小时)
    curl http://100.100.100.200/latest/meta-data/instance/last-host-landing-time
    #实例规格的出方向内网最大带宽。单位:Kbit/s。
    curl http://100.100.100.200/latest/meta-data/instance/max-netbw-egress
    #公网IP
    curl http://100.100.100.200/latest/meta-data/eipv4
    #地区信息等
    curl http://100.100.100.200/latest/meta-data/region-id
    #实例id
    curl http://100.100.100.200/latest/meta-data/instance-id

    4、直接获取ip、mac、实例id、地区等信息

    curl http://100.100.100.200/latest/dynamic/instance-identity/document

    三、接口信息展示

    [root@keep-1 ~]# #获取网卡mac地址
    [root@keep-1 ~]# MAC=`curl -s http://100.100.100.200/latest/meta-data/network/interfaces/macs/`
    [root@keep-1 ~]# echo $MAC
    00:16:3e:17:b3:66/
    [root@keep-1 ~]# #网卡对应的子网掩码
    [root@keep-1 ~]# curl http://100.100.100.200/latest/meta-data/network/interfaces/macs/${MAC}/netmask -w '
    '
    255.255.240.0
    [root@keep-1 ~]# #网卡主私IP地址
    [root@keep-1 ~]# curl http://100.100.100.200/latest/meta-data/network/interfaces/macs/${MAC}/primary-ip-address -w '
    '
    172.16.208.192
    [root@keep-1 ~]# #网卡的网关地址
    [root@keep-1 ~]# curl http://100.100.100.200/latest/meta-data/network/interfaces/macs/${MAC}/gateway -w '
    '
    172.16.223.253
    [root@keep-1 ~]# #vpc相关
    [root@keep-1 ~]# #使用的vpc实例id
    [root@keep-1 ~]# curl http://100.100.100.200/latest/meta-data/vpc-id -w '
    '
    vpc-bp1iablqhktg3othjvxgb
    [root@keep-1 ~]# #vpc实例的网段
    [root@keep-1 ~]# curl http://100.100.100.200/latest/meta-data/vpc-cidr-block -w '
    '
    172.16.0.0/16
    [root@keep-1 ~]# #使用的交换机实例id
    [root@keep-1 ~]# curl http://100.100.100.200/latest/meta-data/vswitch-id -w '
    '
    vsw-bp1jrn0qgv1xu2gotwqbi
    [root@keep-1 ~]# #交换机网段
    [root@keep-1 ~]# curl http://100.100.100.200/latest/meta-data/vpc-cidr-block -w '
    '
    172.16.0.0/16
    [root@keep-1 ~]# 
    [root@keep-1 ~]# #ecs实例相关
    [root@keep-1 ~]# #实例规格
    [root@keep-1 ~]# curl http://100.100.100.200/latest/meta-data/instance/instance-type -w '
    '
    ecs.c6e.large
    [root@keep-1 ~]# #实例创建时间(+8小时)
    [root@keep-1 ~]# curl http://100.100.100.200/latest/meta-data/instance/last-host-landing-time -w '
    '
    2021-01-14 01:45:02
    [root@keep-1 ~]# #实例规格的出方向内网最大带宽。单位:Kbit/s。
    [root@keep-1 ~]# curl http://100.100.100.200/latest/meta-data/instance/max-netbw-egress -w '
    '
    1228800
    [root@keep-1 ~]# #公网IP
    [root@keep-1 ~]# curl http://100.100.100.200/latest/meta-data/eipv4 -w '
    '
    8.136.109.178
    [root@keep-1 ~]# #地区信息等
    [root@keep-1 ~]# curl http://100.100.100.200/latest/meta-data/region-id -w '
    '
    cn-hangzhou
    [root@keep-1 ~]# #实例id
    [root@keep-1 ~]# curl http://100.100.100.200/latest/meta-data/instance-id -w '
    '
    i-bp1cbcme9e9yb7z1z0y5
    
    [root@keep-1 ~]# #获取ip、mac、实例id、地区等信息
    [root@keep-1 ~]# curl http://100.100.100.200/latest/dynamic/instance-identity/document -w '
    '
    {"zone-id":"cn-hangzhou-j","serial-number":"d79850c5-122c-42e0-af50-db113255d48b","instance-id":"i-bp1cbcme9e9yb7z1z0y5","region-id":"cn-hangzhou","private-ipv4":"172.16.208.192","owner-account-id":"1731503671046081","mac":"00:16:3e:17:b3:66","image-id":"centos_7_9_x64_20G_alibase_20201228.vhd","instance-type":"ecs.c6e.large"}
    

      

  • 相关阅读:
    c++ 11 thread 初试
    java UDP聊天与文件传输
    iOS 基础类解析
    Hadoop HA高可用集群搭建(2.7.2)
    object-c 不定參数的遍历和原理
    9.4 返回更新后的行
    java面向接口编程
    Node.js开发入门—套接字(socket)编程
    shell脚本输出带颜色字体
    shell--read命令
  • 原文地址:https://www.cnblogs.com/zhangb8042/p/14276046.html
Copyright © 2020-2023  润新知