Block IP addresses by Country in 3CX
You may want to block the login or phone registration by IP address in 3CX if you are sure your business will be totally local.
Download the database file
We will use the database file (CSV) from https://db-ip.com/db/download/ip-to-country-lite
Open it with Excel, and format as table, then you can filter by the country code, copy the part you want to block, which will looks like below:
A | B | C | D | |
1 | start IP | End IP | Country | |
2 | 2.16.103.0 | 2.16.103.255 | RU | |
3 | 2.16.154.0 | 2.16.154.255 | RU | |
4 | 2.16.159.0 | 2.16.161.255 | RU | |
5 | 2.16.168.0 | 2.16.168.255 | RU |
User a formula =[@A1]&"-"&[@A2] in D1, apply to all the D column, then D column will looks like: 2.16.103.0-2.16.103.255, select all D column, copy. Select E column, right click, choose selective paste, then choose value.
Convert to CIDR format
The 3CX only accept the CIDR format, so we need to convert the data first.
Doing this manually can be daunting , luckily, we can use an online tool to convert them :
Then copy E column, open https://www.ipconvertertools.com/iprange2cidr#, choose multiple IP ranges, paste your data in the text area. click Calculate.
After a few seconds, it will show the:
Click the Export to CSV, choose Comma separated, Download the CSV file, open with Excel, delete every column except the first one, rename the title to IP, add another two column: expirationDate, and description. The correspond value will be date value : 2119-10-08T14:53:00+00:00 , and a description "Russia", because I copied the IP addresses for Russia.
CIDR | Start IP | End IP | Subnet Mask | Addresses | Hosts | Wildcard mask |
2.16.103.0/25 | 2.16.103.0 | 2.16.103.127 | 255.255.255.128 | 128 | 126 | 0.0.0.127 |
2.16.103.128/26 | 2.16.103.128 | 2.16.103.191 | 255.255.255.192 | 64 | 62 | 0.0.0.63 |
2.16.103.192/27 | 2.16.103.192 | 2.16.103.223 | 255.255.255.224 | 32 | 30 | 0.0.0.31 |
2.16.103.224/28 | 2.16.103.224 | 2.16.103.239 | 255.255.255.240 | 16 | 14 | 0.0.0.15 |
2.16.103.240/29 | 2.16.103.240 | 2.16.103.247 | 255.255.255.248 | 8 | 6 | 0.0.0.7 |
2.16.103.248/30 | 2.16.103.248 | 2.16.103.251 | 255.255.255.252 | 4 | 2 | 0.0.0.3 |
2.16.103.252/31 | 2.16.103.252 | 2.16.103.253 | 255.255.255.254 | 2 | 2 | 0.0.0.1 |
Modified into:
IP | expirationDate | description |
2.16.103.0/25 | 2119-10-08T14:53:00+00:00 | Russia |
2.16.103.128/26 | 2119-10-08T14:53:00+00:00 | Russia |
2.16.103.192/27 | 2119-10-08T14:53:00+00:00 | Russia |
2.16.103.224/28 | 2119-10-08T14:53:00+00:00 | Russia |
2.16.103.240/29 | 2119-10-08T14:53:00+00:00 | Russia |
2.16.103.248/30 | 2119-10-08T14:53:00+00:00 | Russia |
2.16.103.252/31 | 2119-10-08T14:53:00+00:00 | Russia |
Save this as a CSV file, which will be converted into JSON by another online tool.
Convert to the JSON format
https://www.convertcsv.com/csv-to-json.htm
Under Step 1: Select your input, click Choose file and select the CSV file.
Under Step 2: Choose input options (optional), tick
[ { "IP": "2.16.103.0/25", "expirationDate": "2119-10-08T14:53:00+00:00", "description": "Russia" }, { "IP": "2.16.103.128/26", "expirationDate": "2119-10-08T14:53:00+00:00", "description": "Russia" }, ... ]
Import into 3CX
Tag:3cx, country IP range, security
You may also like
-
Time To Move On To VoIP
6 May, 2020 -
Why should use HTTPS instead of HTTP
5 May, 2020