> For the complete documentation index, see [llms.txt](https://developers.oxylabs.io/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://developers.oxylabs.io/products/cn/proxies/residential-proxies/whitelisting-ips.md).

# IP 白名单

学习如何为住宅代理创建或编辑 IP 白名单。

IP 白名单允许您只需通过白名单 IP 连接即可访问我们的住宅代理池。

{% hint style="info" %}
你只能添加 IPv4 格式（xx.xx.xx.xx）的 IP。请确保你添加的 IP 是你自己的，并且你在 **当时没有使用代理或 VPN 服务** 时。
{% endhint %}

## 创建 IP 白名单

要将 IP 地址加入白名单，请登录到 [**控制面板**](https://dashboard.oxylabs.io/)，在左侧选择 **住宅代理** → **白名单**，点击 **编辑白名单**。输入 **最多 10 个 IP** 以文本格式，然后点击提交。

{% hint style="info" %}
如果区分代理用户之间的流量统计很重要，我们建议不要使用白名单 IP 功能，尤其是在同一个公网 IP 可能会被服务用户（团队、部门等）共享的情况下。

**注意：** 如果使用浏览器或无头浏览器，它将尝试在没有常规认证的情况下使用代理，并且只会在收到一个 `407`.
{% endhint %}

如果你想删除或更新列表，请将其作为文本文档编辑，然后点击 **提交**。如果你需要更多 IP，请联系我们的客户支持团队，联系邮箱： [**support@oxylabs.io**](mailto:support@oxylabs.io) 或通过我们网站上的 24/7 在线聊天 [**网站**](https://oxylabs.io/) 或者您的 Oxylabs 仪表板。IP 白名单允许您只需通过白名单 IP 连接即可访问我们的住宅代理池。

## 使用白名单 IP 的请求

使用白名单 IP，您可以访问 Oxylabs 住宅代理 **而无需提供一个 `用户名` 和 `密码`**。通过将您的 IP 地址加入白名单，您可以指定所有代理参数 **直接在子域名中。**

如果您将 IP 添加到白名单，您应使用 **白名单 IP 或凭据二者之一**，但不能同时使用，因为这样可能会导致意外行为。

### 代码示例

以下是一个使用给定会话 ID 定向纽约市的示例代码：

{% tabs %}
{% tab title="cURL" %}

```shell
curl -x https://cc-us-city-new_york-sessid-test123.bc.pr.oxylabs.io:7777 https://ip.oxylabs.io/location
```

{% endtab %}

{% tab title="PHP" %}

```php
<?php
$session_id = 'test123';  // Your session ID
$city = 'new_york';  // The city you want to target
$proxy = "cc-us-city-$city-sessid-$session_id.bc.pr.oxylabs.io:7777";
$query = curl_init('https://ip.oxylabs.io/location');

curl_setopt($query, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($query, CURLOPT_PROXY, "http://$proxy");
$output = curl_exec($query);
curl_close($query);

if ($output)
    echo $output;
?>

```

{% endtab %}

{% tab title="Python" %}

```python
import urllib.request

session_id = 'test123'  # Your session ID
city = 'new_york'  # The city you want to target
proxy = 'cc-us-city-%s-sessid-%s.bc.pr.oxylabs.io:7777' % (city, session_id)

query = urllib.request.ProxyHandler({
    'http': proxy,
    'https': proxy,
})

execute = urllib.request.build_opener(query)
print(execute.open('https://ip.oxylabs.io/location').read())

```

{% endtab %}

{% tab title="Java" %}

```java
package example;

import org.apache.http.HttpHost;
import org.apache.http.client.fluent.*;

public class Example {
    public static void main(String[] args) throws Exception {
        HttpHost entry = new HttpHost("cc-us-city-new_york-sessid-test123.bc.pr.oxylabs.io", 7777);

        String query = Executor.newInstance()
            .execute(Request.Get("http://ip.oxylabs.io/location").viaProxy(entry))
            .returnContent().asString();
        
        System.out.println(query);
    }
}

```

{% endtab %}

{% tab title="C#" %}

```csharp
using System;
using System.Net;

class Example
{
    static void Main()
    {
        var client = new WebClient();
        
        client.Proxy = new WebProxy("cc-us-city-new_york-sessid-test123.bc.pr.oxylabs.io:7777");

        Console.WriteLine(client.DownloadString("https://ip.oxylabs.io/location"));
    }
}

```

{% endtab %}

{% tab title="Go" %}

```ruby
package main

import (
	"fmt"
	"io/ioutil"
	"net/http"
	"net/url"
)

func main() {
	proxyURL, _ := url.Parse("https://cc-us-city-new_york-sessid-test123.bc.pr.oxylabs.io:7777")
	client := &http.Client{Transport: &http.Transport{Proxy: http.ProxyURL(proxyURL)}}

	resp, err := client.Get("https://ip.oxylabs.io/location")
	if err != nil {
		fmt.Println("Error:", err)
		return
	}
	defer resp.Body.Close()

	body, _ := ioutil.ReadAll(resp.Body)
	fmt.Println(string(body))
}
```

{% endtab %}
{% endtabs %}

### **查询参数**

| 参数           | 描述                                                                                                                                                                                                                                                                                                                                                    |
| ------------ | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `cc`         | 不区分大小写的两字母国家/地区代码 [**3166-1 alpha-2 格式**](https://en.wikipedia.org/wiki/ISO_3166-1_alpha-2)。例如， `DE` 德国使用， `GB` 英国使用， `TH` 泰国使用。有关如何使用按国家/地区指定的代理的更多详情， [**这里**](/products/cn/proxies/residential-proxies/location-settings/select-country.md).                                                                                                       |
| `城市`         | 不区分大小写的英文城市名。此参数必须与 `cc` 配合以提高准确性，例如， `cc-GB-city-london` 伦敦，英国使用； `cc-DE-city-berlin` 柏林，德国使用。对于包含两个以上单词的城市，将空格替换为 `_`，例如， `city-st_petersburg` 还是 `city-rio_de_janeiro`。点击 [**这里**](https://developers.oxylabs.io/proxies/residential-proxies/location-settings/select-city) 以了解更多城市级定位信息。                                                          |
| `st`         | 不区分大小写的美国州名，前缀为 us\_，例如， `us_california`, `us_illinois`. [**点击此处** ](https://developers.oxylabs.io/proxies/residential-proxies/location-settings/select-state)以了解更多州级定位信息。                                                                                                                                                                            |
| `cn`         | 要从七大洲中的任一洲获取代理，请添加 `cn-` 将参数和两字母代码添加到授权字符串中。点击此处了解更多关于洲级定向的信息                                                                                                                                                                                                                                                                                         |
| `postalcode` | <p>要通过邮政编码连接代理，请添加并指定 <code>postalcode</code> 参数，并使用一个 <strong>五位数的</strong> 邮政编码。此参数必须与国家代码参数结合使用 <code>cc</code> 以及一个不区分大小写的 2 字母国家代码 <a href="https://en.wikipedia.org/wiki/ISO_3166-1_alpha-2"><strong>3166-1 alpha-2 格式</strong></a>.<br><a href="/products/cn/proxies/residential-proxies/location-settings/zip-postal-code.md">在此了解更多。</a></p> |
| `ASN`        | 您可以选择来自特定运营商的代理。您需要在请求中输入所需的 ASN 编号。了解更多 [**这里**](/products/cn/proxies/residential-proxies/location-settings/asn-targeting.md).                                                                                                                                                                                                                       |
| `sessid`     | 会话 ID，用于在后续查询中保持相同 IP。会话在 10 分钟后过期。之后，该会话 ID 会被分配新的 IP 地址。支持随机字符串、0-9 和 A-Z 字符。                                                                                                                                                                                                                                                                       |
| `sesstime`   | 会话时间参数会在一定时间内保持相同 IP。最大会话时间为 30 分钟。                                                                                                                                                                                                                                                                                                                   |


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## 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, and the optional `goal` query parameter:

```
GET https://developers.oxylabs.io/products/cn/proxies/residential-proxies/whitelisting-ips.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

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.
