Skip to content

ts ip-countries ​

Import the IP-to-country data that named locations' countries are judged by, or look up the country of one address. Import it before you rely on a location that holds countries, and again each month to keep it current.

Usage ​

text
ts ip-countries <ip>
ts ip-countries import <file.csv | file.csv.gz>

Description ​

A named location can hold countries, and an address matches one only through IP-to-country data. A new server has none. Until you import it, a location's countries match no address, and a location that includes unknown countries matches every address, since every address is in no country. While the data is missing, a location's page and an application's Access tab in the Administration site warn wherever a location relies on countries, and point here: ts ip-countries import is how the data gets in.

import replaces every range at once with the file's. The file is CSV with no header row, one range per row: a start address, an end address, and a two-letter country code. IPv4 and IPv6 rows can be mixed:

text
198.51.100.0,198.51.100.255,GB
2001:db8::,2001:db8:ffff:ffff:ffff:ffff:ffff:ffff,DE

A row with another number of fields, an address that does not parse, an end before its start, or a code that is not two letters rejects the whole file, and the data already there stays as it was. ts accepts the file gzipped or not, telling the two apart by content rather than name, and uploads the CSV uncompressed; the server accepts up to 128 MB. Each import is recorded in the audit log with the file name and the number of ranges.

DB-IP's free IP to Country Lite database is in this format and is updated monthly. Download the CSV and import it as it comes; import each new month the same way. It is licensed CC BY 4.0, which asks you to credit DB-IP.com wherever its results are shown.

ts ip-countries <ip> prints the country code and English name the data gives an address, or (unknown) when no imported range contains it, which is every address before an import.

Both forms need a Server Administrator: sign in as one, or run on the server with --local.

Options ​

ts ip-countries has no options of its own.

Examples ​

bash
# Load this month's DB-IP data on the server itself
ts --local ip-countries import dbip-country-lite-2026-10.csv.gz

# The same from a workstation, signed in as a Server Administrator
ts ip-countries import ~/Downloads/dbip-country-lite-2026-10.csv

# Which country does the data place an address in?
ts ip-countries 198.51.100.7
bash
# An import replaces every range. A file that covers only some countries
# leaves every other address in no country, where a location that includes
# unknown countries matches it.
ts ip-countries import gb-only.csv

Output ​

text
Imported 612453 IP-country ranges from 'dbip-country-lite-2026-10.csv.gz'.
text
198.51.100.7: GB (United Kingdom)
192.0.2.1: (unknown)

Exit Codes ​

0 on success, including a lookup that prints (unknown). -1 when the argument is not an IPv4 or IPv6 address, and when the server rejects the file, which leaves the existing data unchanged. -4 when no account is signed in. -5 when the account is not a Server Administrator. -6 when the file does not exist.

  • ts location — The named locations whose countries this data places addresses in.
  • ts audit — When the data was last imported, and by whom.