# DescribeSubnets

## 1. 接口描述

本接口(DescribeSubnets)用于查询子网列表信息。可以根据子网ID, 名称等信息筛选查询子网。

## 2. 请求参数

以下请求参数列表仅列出了接口中需要的请求参数

| 参数名称             | 必选 | 类型              | 描述                                             |
| ---------------- | -- | --------------- | ---------------------------------------------- |
| subnetIds        | 否  | Array of String | 根据子网的ID进行筛选。                                   |
| name             | 否  | String          | <p>根据子网的名称进行筛选。</p><p>该字段支持模糊搜索。</p>           |
| cidrBlock        | 否  | String          | 根据子网的CIDR进行筛选。                                 |
| regionId         | 否  | String          | 根据子网所在的节点进行筛选。                                 |
| pageSize         | 否  | Integer         | <p>返回的分页大小。</p><p>可选值范围：\[1, 1000]</p>         |
| pageNum          | 否  | Integer         | <p>返回的分页数。</p><p>可选值范围：\[1, +)</p><p>默认值：1</p> |
| vpcIds           | 否  | Array of String | VPC的ID集合。                                      |
| dhcpOptionsSetId | 否  | String          | 子网绑定的DHCP 选项集ID。                               |

## 3. 响应结果

| 参数名称       | 类型                                                                                                         | 描述                                                       |
| ---------- | ---------------------------------------------------------------------------------------------------------- | -------------------------------------------------------- |
| requestId  | String                                                                                                     | <p>唯一请求 ID。</p><p>每次请求都会返回。定位问题时需要提供该次请求的 requestId。</p> |
| totalCount | Integer                                                                                                    | 符合条件的数据总数。                                               |
| dataSet    | Array of [SubnetInfo](https://docs.console.zenlayer.com/api-reference/cn/compute/datastructure#subnetinfo) | 子网的结果集。                                                  |

## 4. 代码示例

{% tabs %}
{% tab title="示例" %}
**1.查询CidrBlock为`10.0.0.0/24`的Subnet列表。**

```json
POST /api/v2/zec HTTP/1.1
Host: console.zenlayer.com
Content-Type: application/json
X-ZC-Action: DescribeSubnets
<Common Request Params>

Request:
{
  "cidrBlock": "10.0.0.0/24",
  "pageSize": 10,
  "pageNum": 1
}

Response:
{
  "requestId": "TBFC01FCF-6439-4530-ADBC-16809F0C3E8F",
  "response": {
    "requestId": "TBFC01FCF-6439-4530-ADBC-16809F0C3E8F",
    "dataSet": [
      {
        "subnetId": "<subnetId>",
        "regionid": "asia-east-1",
        "name": "Test",
        "cidrBlock": "10.0.0.0/24",
        "gatewayIpAddress": "10.0.0.1",
        "ipv6GatewayIpAddress": "2001:2:0:xx::1",
        "ipv6CidrBlock": "2001:2:0:xx::/64",
        "stackType": "IPv4_IPv6",
        "ipv6Type": "Public",
        "vpcId": "<vpcId>",
        "vpcName": "Test",
        "usageIpv4Count": 253,
        "usageIpv6Count": 1,
        "createTime": "2022-01-01T01:00:00Z",
        "isDefault": true,
        "dhcpOptionsSetId": null
      }
    ],
    "totalCount": 1
  }
}
```

{% endtab %}
{% endtabs %}

## 5. 开发者工具

Zenlayer Cloud API 2.0 提供了配套的[开发工具集（SDK）](https://docs.console.zenlayer.com/api-reference/cn/api-introduction/toolkit)，未来会陆续支持更多开发语言，方便快速接入和使用Zenlayer的产品和服务。

## 6. 错误码

下面包含业务逻辑中遇到的错误码，其他错误码见[公共错误码](https://docs.console.zenlayer.com/api-reference/cn/api-introduction/instruction/commonerrorcode)

| HTTP状态码 | 错误码 | 说明 |
| ------- | --- | -- |


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.console.zenlayer.com/api-reference/cn/compute/zec/vpc-network/describesubnets.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
