# Geographic targeting

> Filter exits by country, by region, by state, or by network.
>
> Web page: https://ports.io/docs/reference/targeting/
> Documentation index: https://ports.io/llms.txt

Use region and country clauses in your proxy username to restrict the exits eligible for a new connection. Filters select from available exits; they do not reserve capacity or guarantee availability in a location.

The same geographic clauses work with HTTP and SOCKS5 proxy authentication. They belong in the routing username, while the full proxy key is the password.

## Target a country

Use a two-letter ISO country code:

```text
v1_rotate_countries_US
```

To allow several countries, separate codes with commas:

```text
v1_rotate_countries_US,GB
```

This permits an exit in either the United States or the United Kingdom. The singular spelling `country` is accepted as an alias for `countries`:

```text
v1_rotate_country_US
```

Use `countries` consistently when generating usernames programmatically.

## Target a region

Use `NA`, `SA`, `AF`, `AS`, or `EU`. Multiple region codes use hyphens:

```text
v1_rotate_regions_NA-EU
```

This permits exits in North America or Europe. See the [region table](https://ports.io/docs/reference/username-reference.md#supported-regions) for names.

Exits in Oceania, such as Australia and New Zealand, have no region code. Target them by country, with `AU` or `NZ`.

## Combine filters

Regions and countries add up: an exit is eligible if it is in any listed region or any listed country. Exclusions are then removed from that set.

```text
v1_rotate_regions_NA_countries_BR_exclude_MX
```

This permits exits anywhere in North America plus Brazil, then removes Mexico.

| Username filters | Eligible geography |
| --- | --- |
| No geographic clauses | Any eligible exit |
| `_countries_US,GB` | US or United Kingdom |
| `_regions_NA-EU` | North America or Europe |
| `_regions_EU_countries_BR` | Europe or Brazil |
| `_regions_EU_exclude_RU,BY` | Europe except Russia and Belarus |
| `_countries_US,GB_exclude_GB` | US only |
| `_countries_US_exclude_US` | Empty selection |

The last example is syntactically valid but cannot match an exit. Listing a country inside a listed region adds nothing: `_regions_EU_countries_DE` is all of Europe. To narrow a region, list its countries instead, or exclude the ones you don't want.

## Target a state or province

Use `states` with ISO 3166-2 style codes: the country code, a hyphen, and the code of the country's top-level subdivision. Separate several with commas:

```text
v1_rotate_states_US-IL
v1_rotate_states_US-IL,US-WI,CA-ON
```

This permits an exit in any listed state. The singular spelling `state` is accepted as an alias for `states`.

`states` is applied on top of the other filters, not added to them: `_countries_US_states_US-IL` is Illinois, and `_countries_GB_states_US-IL` matches nothing. A state whose country is in `exclude` is rejected as invalid.

A state's location comes from IP geolocation of the exit's address, at the first level of subdivision: states in the US, provinces in Canada, `GB-ENG` rather than a London borough. It is reliable for home broadband but less so for mobile networks, whose addresses often geolocate to the carrier's gateway in another state.

A selection narrowed to states needs a minimum number of online exits, as a targeted network does. Below that, the request returns `no_exit_available`. Listing neighboring states together widens the pool.

## Target a network

Use `asn` with one autonomous system number to keep only exits on that network. The `AS` prefix is optional:

```text
v1_rotate_asn_7922
v1_rotate_countries_US_asn_AS7922
```

`asn` is applied on top of the geographic filters, including `states`. It takes one number; to spread traffic over several networks, use a different username per network.

A network needs a minimum number of online exits before it can be targeted. Below that, or for a network with no exits, the request returns `no_exit_available`. Small networks can drop under the minimum at quiet hours.

## Apply targeting to a session

The same filter clauses work with sticky and fixed strategies:

```text
v1_sticky_session_checkout-42_countries_US
v1_fixed_session_audit-42_countries_DE,FR
```

Keep the strategy and geographic policy stable for an existing session ID. Create a new session ID when changing its policy. Reusing an active ID with different filters can produce a session policy conflict during connection setup.

## Handle unavailable locations

When no eligible exit matches the request, HTTP proxying returns `502 no_exit_available`; SOCKS5 returns a general-failure CONNECT reply (`0x01`). A valid country code can still have no active exits. See [Troubleshooting](https://ports.io/docs/reference/troubleshooting.md) for protocol-specific errors.

Review exclusions that remove every listed country first, then consider a broader selection appropriate to your application. Do not silently broaden geography when your application requires a specific location.

The username grammar currently has no city, postal-code, or carrier-name selector. A region or country filter refers to the exit's location metadata, not the destination website's location.
