Skip to content

Commit

Permalink
Added support for IP2Location.io API
Browse files Browse the repository at this point in the history
  • Loading branch information
ip2location committed Jul 31, 2024
1 parent 33b4343 commit d8d55d7
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 6 deletions.
3 changes: 2 additions & 1 deletion docs/privacy.md
Original file line number Diff line number Diff line change
Expand Up @@ -118,9 +118,10 @@ Dashy supports [Widgets](/docs/widgets.md) for displaying dynamic content. Below
- [OWM Privacy Policy](https://openweather.co.uk/privacy-policy)
- **[RSS Feed](/docs/widgets.md#rss-feed)**: `https://api.rss2json.com/v1/api.json`
- [Rss2Json Privacy Policy](https://rss2json.com/privacy-policy)
- **[IP Address](/docs/widgets.md#public-ip)**: `https://ipapi.co/json` or `http://ip-api.com/json`
- **[IP Address](/docs/widgets.md#public-ip)**: `https://ipapi.co/json` or `http://ip-api.com/json` or `https://api.ip2location.io/`
- [IPGeoLocation Privacy Policy](https://ipgeolocation.io/privacy.html)
- [IP-API Privacy Policy](https://ip-api.com/docs/legal)
- [IP2Location.io Privacy Policy](https://ip2location.io/privacy-policy)
- **[IP Blacklist](/docs/widgets.md#ip-blacklist)**: `https://api.blacklistchecker.com`
- [Blacklist Checker Privacy Policy](https://blacklistchecker.com/privacy)
- **[Domain Monitor](/docs/widgets.md#domain-monitor)**: `http://api.whoapi.com`
Expand Down
8 changes: 4 additions & 4 deletions docs/widgets.md
Original file line number Diff line number Diff line change
Expand Up @@ -287,7 +287,7 @@ Unless image fetched from remote source, no external data request is made.

### Public IP

Often find yourself searching "What's my IP", just so you can check your VPN is still connected? This widget displays your public IP address, along with ISP name and approx location. Data can be fetched from either [IpApi.co](https://ipapi.co/), [IP-API.com](https://ip-api.com/) or [IpGeolocation.io](https://ipgeolocation.io/).
Often find yourself searching "What's my IP", just so you can check your VPN is still connected? This widget displays your public IP address, along with ISP name and approx location. Data can be fetched from either [IpApi.co](https://ipapi.co/), [IP-API.com](https://ip-api.com/), [IpGeolocation.io](https://ipgeolocation.io/) or [IP2Location.io](https://ip2location.io/).

<p align="center"><img width="400" src="https://i.ibb.co/vc3c8zN/public-ip.png" /></p>

Expand All @@ -297,8 +297,8 @@ _All fields are optional._

**Field** | **Type** | **Required** | **Description**
--- | --- | --- | ---
**`provider`** | `string` | _Optional_ | The name of the service to fetch IP address from. Can be either `ipapi.co`, `ip-api` or `ipgeolocation`. Defaults to `ipapi.co`. Note, `ip-api` doesn't work on HTTPS, and if you set to `ipgeolocation` then you must also provide an API key
**`apiKey`** | `string` | _Optional_ | Only required if provider is set to `ipgeolocation`. You can get a free API key [here](https://ipgeolocation.io/signup.html)
**`provider`** | `string` | _Optional_ | The name of the service to fetch IP address from. Can be either `ipapi.co`, `ip-api`, `ipgeolocation` or `ip2location.io`. Defaults to `ipapi.co`. Note, `ip-api` doesn't work on HTTPS, and if you set to `ipgeolocation` or `ip2location.io` then you must also provide an API key
**`apiKey`** | `string` | _Optional_ | Only required if provider is set to `ipgeolocation` or `ip2location.io`. You can get a free IPGeolocation API key [here](https://ipgeolocation.io/signup.html) or a free IP2Location.io API key [here](https://ip2location.io/pricing)

#### Example

Expand All @@ -321,7 +321,7 @@ Or
- **Auth**: 🟠 Optional
- **Price**: 🟢 Free
- **Host**: Managed Instance Only
- **Privacy**: _See [IPGeoLocation Privacy Policy](https://ipgeolocation.io/privacy.html) or [IP-API Privacy Policy](https://ip-api.com/docs/legal)_
- **Privacy**: _See [IPGeoLocation Privacy Policy](https://ipgeolocation.io/privacy.html) or [IP-API Privacy Policy](https://ip-api.com/docs/legal) or [IP2Location.io Privacy Policy](https://ip2location.io/privacy-policy)

---

Expand Down
11 changes: 10 additions & 1 deletion src/components/Widgets/PublicIp.vue
Original file line number Diff line number Diff line change
Expand Up @@ -24,17 +24,20 @@ export default {
endpoint() {
if (this.provider === 'ipgeolocation') {
return `${widgetApiEndpoints.publicIp2}?apiKey=${this.apiKey}`;
} else if (this.provider === 'ip2location.io') {
return `${widgetApiEndpoints.publicIp4}?key=${this.apiKey}`;
} else if (this.provider === 'ipapi') {
return widgetApiEndpoints.publicIp3;
}
return widgetApiEndpoints.publicIp;
},
apiKey() {
if (this.provider === 'ipgeolocation' && !this.options.apiKey) this.error('Missing API Key');
if (this.provider === 'ip2location.io' && !this.options.apiKey) this.error('Missing API Key');
return this.options.apiKey;
},
provider() {
// Can be either `ip-api`, `ipapi.co` or `ipgeolocation`
// Can be either `ip-api`, `ipapi.co`, `ipgeolocation` or `ip2location.io`
return this.parseAsEnvVar(this.options.provider) || 'ipapi.co';
},
},
Expand Down Expand Up @@ -72,6 +75,12 @@ export default {
this.location = `${ipInfo.city}, ${ipInfo.regionName}`;
this.flagImg = getCountryFlag(ipInfo.countryCode);
this.mapsUrl = getMapUrl({ lat: ipInfo.lat, lon: ipInfo.lon });
} else if (this.provider === 'ip2location.io') {
this.ipAddr = ipInfo.ip;
this.ispName = ipInfo.isp || 'IP2Location.io Starter plan or higher required.';
this.location = `${ipInfo.city_name}, ${ipInfo.region_name}`;
this.flagImg = getCountryFlag(ipInfo.country_code);
this.mapsUrl = getMapUrl({ lat: ipInfo.latitude, lon: ipInfo.longitude });
} else {
this.error('Unknown API provider fo IP address');
}
Expand Down
1 change: 1 addition & 0 deletions src/utils/defaults.js
Original file line number Diff line number Diff line change
Expand Up @@ -244,6 +244,7 @@ module.exports = {
publicIp: 'https://ipapi.co/json',
publicIp2: 'https://api.ipgeolocation.io/ipgeo',
publicIp3: 'http://ip-api.com/json',
publicIp4: 'https://api.ip2location.io/',
readMeStats: 'https://github-readme-stats.vercel.app/api',
rescueTime: 'https://www.rescuetime.com/anapi/data',
rssToJson: 'https://api.rss2json.com/v1/api.json',
Expand Down

0 comments on commit d8d55d7

Please sign in to comment.